Skip to content
Related Articles

Related Articles

Method of guessing and confirming
  • Difficulty Level : Easy
  • Last Updated : 20 Jan, 2021

The basic idea behind this method is to guess the answer, and then prove it correct by induction. This method can be used to solve any recurrence. If a solution is guessed and then try to verify our guess inductively, usually either the proof will succeed (in that case we are done), or the proof will fail (in that case the failure will help us refine our guess).

For example, consider the recurrence: T(N) = √N*T(√N) + N. This doesn’t fit into the form required by the Master Theorems. Carefully observing the recurrence gives us the impression that it is similar to the divide and conquer method (diving the problem into √N subproblems each with size √N). As it can be seen that, the size of the subproblems at the first level of recursion is N. So, let us guess that T(N) = O(N*log N), and then try to prove that the guess is correct.

Let’s start by trying to prove an upper bound:

T(N) \le cN*logN:

T(N) = √N*T(√N) + N



T(N) \le √N* c√N*log√N + N

T(N) = N* clog√N + N

T(N) = N*1/2*c*log N + N

T(N) \le cN*log N

The last inequality assumes only that 1 \le 1/2*clog N. This is correct if N is sufficiently large and for any constant c, no matter how small. 

From the above proof, we can see that our guess is correct for the upper bound. Now, let us prove the lower bound for this recurrence:

T(N) = √N*T(√N) + N

T(N) \ge  √N* k√N*log√N + N



T(N) = N* klog√N + N

T(N) = N*1/2*k*log N + N

T(N) \ge  N*k*log N

The last inequality assumes only that 1 \ge  1/2*k*log N. This is incorrect if N is sufficiently large and for any constant k.

From the above proof, we can see that our guess is incorrect for the lower bound.

From the above discussion, it can be understood that Θ(N*log N) is too big. But how about Θ(N)? The lower bound is easy to prove directly:

T(N) = √N*T(√N) + N \ge  N

Now, let us prove the upper bound for this Θ(N):
T(N) = √N*T(√N) + N\\ \le √N*c√N + N\\ = N c+ N\\ = N (c + 1)\\ \nleq cN

From the above induction, it can be understood that Θ(N) is too small and Θ(N*log N) is too big. So, we need something bigger than N and smaller than N*log N? How about N*√log N?

Proving upper bound for N*√log N:

T(N) = √N*T(√N) + N

T(N) \le √n*c√N*√(log √N) + N

T(N) = N* 1/√2 *c*log √N + N

T(N) \le N*c*log √N

Proving lower bound for N*√log N:

T(N) = √N*T(√N) + N

T(N) \ge  √N*k√N*√(log√N) + N

T(N) = N*1/√2*k*log √N + N

T(N) \ngeq N*k*log √N

The last step doesn’t work. So, Θ(N*√log N) doesn’t work. What else is between N and N*log N? How about N*log(log N)?

Proving upper bound for N*log(log N):

T(N) = √N*T(√N) + N
T(N) \le √N*c√N*log(log √N) + N
T(N) = N*clog(log N) - cN + N
T(N) \le N*clog(log N), if \ c\ge 1

Proving lower bound for N*log(log N):

T(N) = √N*T(√N) + N

T(N) \ge  √N*k√N*log(log √N) + N

T(N) = N*k*log(log N) - kN + N

T(N) \ge  N*klog(log N), if \ k \le 1

From the above proofs, it can see that T(N) \le N*clog(log N), if \ c \ge  1 and T(N) \ge  N*klog(log N), if \ k \le 1.
Technically, we’re still missing the base cases in both proofs, but we can be fairly confident at this point that T(N) = Θ(N*log(log N)).

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :