-3

I am studying about recurrences using my friend's pdf (Algorithms Unlocked) and trying to solve the problems about recurrences and it is not yet clear to me about the mechanics of the recursion tree(I assume this is the method to be used on this problem) and how to make bounds tight for example I want the constant to be small?

Salvador Dali
  • 214,103
  • 147
  • 703
  • 753
Simoun
  • 25
  • 1
  • 2

2 Answers2

1

Try to expand your recurence using a recursive tree. You will have something like this:

Recursive tree for T(n)

See that each level has a non-recursive complexity = n By extending T(n), we have 2 subtrees with different heights. You can see the 2 heights H1 and H2.

Now T(n) is bounded by the complexity of the 2 subtrees: n * H1 >= T(n) >= n * H2

Where: H1 = 1+log_2(n) and H2 = 1+log_4(n)

So the solution will be O(nlog_2(n))

User12345
  • 44
  • 2
0

First of all, take a look at the suggestion given here and try to do something before posting the question. I answer this only because I found it interesting to refresh my skills.


The solution is O(n log(n)).

So you have to see that Master theorem will not work here, but Akra-Bazzi will work.

So here g(n) = n, a1 = 1, b1 = 1/2, a2 = 2, b2=1/4. Solving the equation: a1*b1^p + a2*b2^p = 1 you get p = 1.

Now solving the integral int(1/u)du from 1 to x you will get log(x). So the complexity is O(x(1+log(x)) which is O(nlog(n)) where O is a tight bound.

Community
  • 1
  • 1
Salvador Dali
  • 214,103
  • 147
  • 703
  • 753
  • Thanks for the help. I am wondering if recursion tree method will work in this problem ? because in the book only substitution, recursion tree and the master theorem are in the recurrences lesson. thanks – Simoun Dec 08 '15 at 10:47
  • Yes, recursion unrolling would work, I just wanted to practice Akra-Bazzi, because I already unrolled two recursions today. – Salvador Dali Dec 08 '15 at 10:51
  • I see, I just wanna ask if can you use the recursion tree method so I can follow what is happening because I am not familiar with Akra-Bazzi and I am currently learning recursion tree method. Thank you very much – Simoun Dec 08 '15 at 11:11