Wednesday, July 3, 2024
HomeData ModellingData Structure & AlgorithmMethod of guessing and confirming

Method of guessing and confirming

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

Feeling lost in the world of random DSA topics, wasting time without progress? It’s time for a change! Join our DSA course, where we’ll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 neveropen!

Calisto Chipfumbu
Calisto Chipfumbuhttp://cchipfumbu@gmail.com
I have 5 years' worth of experience in the IT industry, primarily focused on Linux and Database administration. In those years, apart from learning significant technical knowledge, I also became comfortable working in a professional team and adapting to my environment, as I switched through 3 roles in that time.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments