Open In App

Method of guessing and confirming

Last Updated : 02 Nov, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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: [Tex]T(N) = √N*T(√N) + N [/Tex]T(N) \le √N* c√N*log√N + N [Tex]T(N) = N* clog√N + N [/Tex]T(N) = N*1/2*c*log N + N [Tex]T(N) ≤ cN*log N [/Tex]


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 [Tex]T(N) ≥ √N* k√N*log√N + N [/Tex]T(N) = N* klog√N + N [Tex]T(N) = N*1/2*k*log N + N [/Tex]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 [Tex]T(N) ≤ √n*c√N*√(log √N) + N [/Tex]T(N) = N* 1/√2 *c*log √N + N [Tex]T(N) ≤ N*c*log √N [/Tex]


Proving lower bound for N*√log N :

T(N) = √N*T(√N) + N [Tex]T(N) ≥ √N*k√N*√(log√N) + N [/Tex]T(N) = N*1/√2*k*log √N + N [Tex]T(N) \ngeq N*k*log √N [/Tex]


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 [Tex]T(N) ≤ √N*c√N*log(log √N) + N [/Tex]T(N) = N*clog(log N) - cN + N [Tex]T(N) ≤ N*clog(log N), if \ c≥1 [/Tex]


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

T(N) = √N*T(√N) + N [Tex]T(N) ≥ √N*k√N*log(log √N) + N [/Tex]T(N) = N*k*log(log N) - kN + N [Tex]T(N) ≥ N*klog(log N), if \ k ≤ 1 [/Tex]


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)) .



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads