Search code examples
algorithmrecursionbig-omaster-theorem

Solving a recurrence of Time complexity involving Theta notation


T(n) = 4T(n/2) + Θ(n^2 /logn)

How do I solve this recurrence? I cannot use the Master theorem here.


Solution

  • Without using Master theorem, just simply keep expanding the recurrence relation until you see a pattern.

    T(n) = 4T(n/2) + Θ(n^2 /log(n))
    = 4*(4t(n/4) + theta((n/2)^2 / log(n/2))) + theta(n^2/log(n)) 
    = 4^2 * (t(n/4) + theta((n/2)^2 / log(n/2)) / 4) + theta(n^2/log(n)) 
    theta((n/2)^2 / log(n/2)) / 4 can be simplified to theta(n^2/log(n))
    = 4^2 * (t(n/4)) + 2theta(n^2/log(n)) 
    = 4^2 * (4t(n/8) + theta((n/4)^2 / log(n/4))) + 2theta(n^2/log(n)) 
    = 4^3 * (t(n/8) + theta((n/4)^2 / log(n/4)) / 4) + 2theta(n^2/log(n)) 
    theta((n/4)^2 / log(n/4)) / 4 can be simplified to theta(n^2/log(n))
    = 4^3 * (t(n/8)) + 3theta(n^2/log(n)) 
    

    So we can further simplify this to

    4^k * (t(n/k)) + k*theta(n^2/log(n)) 
    

    This will keep going until k = n, and assuming T(1) = 1, we get

    4^n + n*theta(n^2/log(n))
    

    And since 4^n is greater than n*theta(n^2/log(n)), the answer is O(4^n).