Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Algorithms | Analysis of Algorithms (Recurrences) | Question 1

  • Difficulty Level : Basic
  • Last Updated : 21 May, 2019

What is the value of following recurrence.

T(n) = T(n/4) + T(n/2) + cn2
T(1) = c
T(0) = 0

Where c is a positive constant

(A) O(n3)
(B) O(n2)
(C) O(n2 Logn)
(D) O(nLogn)

Answer: (B)

Explanation: Following is the initial recursion tree for the given recurrence relation.

         /      \
     T(n/4)     T(n/2)

If we further break down the expression T(n/4) and T(n/2), we get following recursion tree.

           /           \      
       c (n^2)/16       c(n^2)/4
      /      \          /     \
  T(n/16)     T(n/8)  T(n/8)    T(n/4) 

Breaking down further gives us following

            /             \      
       c(n^2)/16           c(n^2)/4
       /      \            /      \
c(n^2)/256  c(n^2)/64  c(n^2)/64    c(n^2)/16
 /    \      /    \    /    \         /    \    

To know the value of T(n), we need to calculate sum of tree nodes level by level. If we sum the above tree level by level, we get the following series
T(n) = c(n^2 + 5(n^2)/16 + 25(n^2)/256) + ….
The above series is geometrical progression with ratio 5/16
To get an upper bound, we can sum the above series for infinite terms. We get the sum as (n^2) / (1 – 5/16) which is O(n^2)

Refer following video lecture for more details.

Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!