0% found this document useful (0 votes)
48 views4 pages

The Recurrence T (N) 2T (n/2) + CN, T (1) D, When N Is A Power of 2 (N 2

The document describes a divide and conquer recursive algorithm to solve a problem of size n. The recurrence relation is T(n) = aT(n/b) + f(n), where a and b are constants and f(n) is the work done at each level. It analyzes the running time of the algorithm using recursion trees.

Uploaded by

Hirak Sarkar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views4 pages

The Recurrence T (N) 2T (n/2) + CN, T (1) D, When N Is A Power of 2 (N 2

The document describes a divide and conquer recursive algorithm to solve a problem of size n. The recurrence relation is T(n) = aT(n/b) + f(n), where a and b are constants and f(n) is the work done at each level. It analyzes the running time of the algorithm using recursion trees.

Uploaded by

Hirak Sarkar
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

The Recurrence T(n) = 2T(n/2) + cn, T(1) = d, when n is a power of 2 (n = 2k, k = lg(n))

Total time
size n
at this level:
time cn
cn

Total time
size n/2 size n/2 at this level:
time cn/2 time cn/2 2(cn/2) = cn

Total time
size n/22 size n/22 size n/22 size n/22
at this level:
time cn/22 time cn/22 time cn/22 time cn/22

k levels
22(cn/22) = cn

Total time
size n/23 size n/23 size n/23 size n/23 size n/23 size n/23 size n/23 size n/23
at this level:
time cn/23 time cn/23 time cn/23 time cn/23 time cn/23 time cn/23 time cn/23 time cn/23
23(cn/23) = cn

Total time
size n/2k-1= 2 2k-1 = n/2 subproblems
at this level:
time cn/2k-1= 2c like this
2 (cn/2k-1) = cn
k-1

Total time
size 1 size 1 2k = n subproblems at this level:
time d time d like this dn

T(n) = total time= k(cn) + dn


= cnlg(n) + dn
= Θ(nlg(n))
The Recurrence T(n) = 3T(n/2) + cn, T(1) = d, when n is a power of 2 (n = 2k, k = lg(n))

Total time
size n
at this level:
time cn
cn

Total time
size n/2 size n/2 size n/2 at this level:
time cn/2 time cn/2 time cn/2 3(cn/2) =
(3/2)cn

k levels
Total time
2 2 2 2 2 2 2 2 2
size n/2 size n/2 size n/2 size n/2 size n/2 size n/2 size n/2 size n/2 size n/2 at this level:
time cn/22 time cn/22 time cn/22 time cn/22 time cn/22 time cn/22 time cn/22 time cn/22 time cn/22 32(cn/22) =
(3/2)2cn

Total time
size n/2k-1= 2 3k-1 subproblems like at this level:
time cn/2k-1= 2c this 3k-1(cn/2k-1) =
(3/2)k-1cn

Total time
size 1 size 1 size 1 3k = 3lg(n) = n lg(3) at this level:
time d time d time d subproblems like this dnlg(3)

T(n) = total time= (1 + 3/2 + (3/2)2 + ... + (3/2)k-1) cn + dnlg(3)


= ((3/2)k-1) / (3/2-1) (cn) + dnlg(3)
= (2c)(3k/2k )n – 2cn + dnlg(3)
= (2c)3k – 2cn + dnlg(3) (since n = 2k)
= (2c + d) nlg(3) – 2cn (3k = 3lg(n) = n lg(3))
= Θ(n lg(3))
The Recurrence T(n) = 3T(n/2) + cn2, T(1) = d, when n is a power of 2 (n = 2k, k = lg(n))

Total time
size n
at this level:
time cn2
cn2

Total time
size n/2 size n/2 size n/2 at this level:
time cn2/22 time cn2/22 time cn2/22 3(cn2/22) =
(3/22)cn2

k levels
Total time
2 2 2 2 2 2 2 2 2
size n/2 size n/2 size n/2 size n/2 size n/2 size n/2 size n/2 size n/2 size n/2 at this level:
time cn2/24 time cn2/24 time cn2/24 time cn2/24 time cn2/24 time cn2/24 time cn2/24 time cn2/24 time cn2/24 32(cn/22) =
(3/22)2cn2

Total time
size n/2k-1= 2 3k-1 subproblems like at this level:
time cn2/22k-2= 4c this 3k-1(cn/2k-1) =
(3/22)k-1cn2

Total time
size 1 size 1 size 1 3k = 3lg(n) = n lg(3) at this level:
time d time d time d subproblems like this dnlg(3)

T(n) = total time = (1 + 3/22 + (3/22)2 + ... + (3/22)k-1) cn2 + dnlg(3)


= ((3/22)k–1)/(3/22–1) cn2 + dnlg(3)
= –4c(3k/22k )n2 + 4cn2 + dnlg(3)
= –4c3k + 4cn2 + dnlg(3) (since n2 = 22k)
= (d – 4c) nlg(3) + 4cn2 (3k = 3lg(n) = n lg(3))
= Θ(n 2)
The Recurrence T(n) = aT(n/b) + f(n), T(1) = d, when n is a power of b (n = bk, k = logb(n))

Total time
size n
at this level:
time f(n)
f(n)

Total time
size n/b Each node has size n/b size n/b
a children at this level:
time f(n/b) time f(n/b) time f(n/b) a f(n/b)

k levels
Total time
size n/b2 size n/b2 size n/b2 size n/b2 size n/b2 size n/b2 size n/b2 size n/b2 size n/b2
at this level:
time f(n/b2) time f(n/b2) time f(n/b2) time f(n/b2) time f(n/b2) time f(n/b2) time f(n/b2) time f(n/b2) time f(n/b2)
a2 f(n/b2)

Total time
a k- 1 = a k/a = n logb(a) /a
k-1
size n/b = b at this level:
subproblems like this
time f(n/bk-1) ak-1 f(n/bk-1) =
(see below). (f(b)/a) nlogb(a)

Total time
size 1 size 1 size 1 a k = a logb(n) = n logb(a) at this level:
time d time d time d subproblems like this. dnlogb(a)

2 2 k-1 k-1 logb(a)


T(n) = total time = f(n) + a f(n/b) + a f(n/b ) + ... + a f(n/b ) + dn

You might also like