Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Tutorial2, Lecture notes of Advanced Computer Programming

read it recursion ...

Typology: Lecture notes

2015/2016

Uploaded on 08/08/2016

Raju.Ranjan
Raju.Ranjan 🇮🇳

1 document

1 / 4

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Princess Nora Bint Abdulrahman University First Semester 1433/1434H
Faculty of Computer and Information Science Tutorial # 2
CS 411 : Algorithms Design and Analysis Recursion Tree
Page ١ of ٤
Q: Regard to the recurrence equation below:
T(n) = 4T(n/2) +n
a. Draw the recursion tree.
b. Determine the number of nodes and cost at each level.
c. Determine the total cost for all levels (i.e. in summation form).
Steps:
1. Draw the tree based on the recurrence
2. From the tree determine:
a. # of levels in the tree
b. cost per level
c. # of nodes in the last level
d. cost of the last level (which is based on the number found in
2c)
3. Write down the summation using ∑ nota*on – this summation
sums up the cost of all the levels in the recursion tree
4. Recognize the sum or look for a closed form solution for the
summa*on created in 3). Use Appendix A.
5. Apply that closed form solution to your summation coming up
with your “guess” in terms of Big-O, or Θ, or Ω (depending on
which type of asymptotic bound is being sought).
pf3
pf4

Related documents


Partial preview of the text

Download Tutorial2 and more Lecture notes Advanced Computer Programming in PDF only on Docsity!

Faculty of Computer and Information Science Tutorial # 2 CS 411 : Algorithms Design and Analysis Recursion Tree

٤of١ Page

Q: Regard to the recurrence equation below:

T(n) = 4T(n/2) +n

a. Draw the recursion tree.

b. Determine the number of nodes and cost at each level.

c. Determine the total cost for all levels (i.e. in summation form).

Steps:

1. Draw the tree based on the recurrence

2. From the tree determine:

a. # of levels in the tree

b. cost per level

c. # of nodes in the last level

d. cost of the last level (which is based on the number found in

2c)

3. Write down the summation using ∑ nota*on – this summation

sums up the cost of all the levels in the recursion tree

4. Recognize the sum or look for a closed form solution for the

summa*on created in 3). Use Appendix A.

5. Apply that closed form solution to your summation coming up

with your “guess” in terms of Big-O, or Θ, or Ω (depending on

which type of asymptotic bound is being sought).

Faculty of Computer and Information Science Tutorial # 2 CS 411 : Algorithms Design and Analysis Recursion Tree

٤of٢ Page

n

T(n/2) T( n/2) T(n/2 ) T( n/2 )

n

n/2 n/2 n/2 n/

T(n/4 ) T(n/4 ) T(n/4 ) T(n/4) - - - - -

n

n/2 n/2 n/2 n/

n/4 n/4 n/4 n/4 - - - - - - - - - -

T(n/8)-----------------------------------------

Solution :

T(n) = 4T(n/2) +n

T(n/2)=4T(n/4)+n/

T(n/4) = 4T(n/8) +(n/4)

Faculty of Computer and Information Science Tutorial # 2 CS 411 : Algorithms Design and Analysis Recursion Tree

٤of٤ Page

〵⡹⡩

〶⢀⡨

2 〵^

from ᡗᡩᡳᡓᡲᡡᡧᡦ #

ᡆ䙦ᡦ䙧 = 4〹あ〴ㄘぁᡆ䙦1䙧 + 㔳 2〶

〵⡹⡩

〶⢀⡨

ᡆ䙦ᡦ䙧 = ᡦ〹あ〴ㄘ^ ⡲^ ᡆ䙦1䙧 + 㔳 2〶

〵⡹⡩

〶⢀⡨

ᡦ〹あ〴ㄘ^ ⡲^ = ᡦ⡰^ ᡱᡡᡦᡕᡗ ᡤᡧᡙ⡰ 4 = 2 ← ᡗᡩᡳᡓᡲᡡᡧᡦ

from ᡗᡩᡳᡓᡲᡡᡧᡦ #

ᡆ䙦ᡦ䙧 = ᡦ⡰ᡆ䙦1䙧 + ᡦ 㔳 2〶

〵⡹⡩

〶⢀⡨ ᡆ䙦ᡦ䙧 = ᡦ⡰ᡆ䙦1䙧 + ᡦ 䙰1 + 2 + 2⡰^ + ⋯.. +2〵⡹⡩䙱 ᠵᡦᡕᡰᡗᡓᡱᡡᡦᡙ ᠳᡗᡧᡥᡗᡲᡰᡡᡕ ᡅᡗᡰᡡᡗᡱ ᡰ = 2 ᡓ = 1

ᡅ = ᡓ + ᡓᡰ + ᡓᡰ⡰^ + … + ᡓᡰ〸⡹⡩^ =

ᡓ䙦ᡰ〸^ − 1䙧

ᡦ 䙰1 + 2 + 2⡰^ + ⋯ + 2〵⡹⡩䙱 =

1䙦2〵^ − 1䙧

= 2〵^ − 1

= 2〹あ〴ㄘぁ^ − 1

= ᡦ〹あ〴ㄘ⡰^ − 1 = ᡦ − 1 ᡅᡡᡦᡕᡗ ᡤᡧᡙ⡰2 = 1

ᡆ䙦ᡦ䙧 = ᡦ⡰^ ᡆ䙦1䙧 + ᡦ䙦ᡦ − 1䙧