Fiction

Stormed by last night’s applause for madness, caught naked in an alley alongside the half-filled garbage bins, waiting for their mouthful of bodies. Fade to a shake. Sometimes the hair leaves the…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Master Theorem

Algorithm Cycle
Image from google

When we have to solve a problem and when many ways are available to solve that problem (for example Matrix chain multiplication problem), at that time analysis of the algorithm is needed.

Analysis of algorithms means to estimate their complexity in an asymptotic sense. The term “analysis of algorithms” was coined by Donald Knuth. Analysis of algorithms is the determination of the amount of time and space resources required to execute it.

Most of the algorithms are recursive in nature, they use the divide and conquer strategy. The recursive algorithm calls itself for the other inputs. That is usually part of the original input but has a smaller size (sub-problem). There are many ways to solve the recurrence relation. They are as follows :

Among all these methods the master theorem is the fastest method to find the time complexity of the function. It is very easy to understand and easy to apply. We just have to remember some cases. So here we go.

In decreasing functions, we are having forms like T(n) = T(n-1)+1, T(n)=2T(n-1)+n² etc.

To solve this type of recurrence relation there are 3 cases :

If a<1 then T(n) = O(n^k) or simply T(n) = O(f(n)).

Examples :

If a = 1 then T(n) = O(n^(k+1)) or simply T(n) = O(n*f(n)).

Examples :

If a>1 then T(n) = O(a^(n/b) * f(n)).’

Examples :

Like decreasing functions, the master theorem can also be applied to dividing functions.

Dividing functions can be defined as T(n) = T(n/2) + c, T(n)=2T(n/2)+logn, etc.

To find the time complexity for these kinds of functions again there are 3 cases. Here we have to find two things 1. loga base b and 2. k

For simplicity, let’s take loga base b as x for all below cases.

If k < x then T(n) = O(n^x).

Examples :

If k = x then again some cases here comes p in the picture :

Examples :

If k > x then T(n) = O(f(n)).

Examples :

In this pretty simple way, Master Theorem works to find the complexity of decreasing and dividing functions.

We can use either Theta (Θ) Notation or Omega (Ω) Notation instead of Big O Notation. Using Θ notation will be more appropriate fo the master theorem.

There are some limitations of this theorem. That is for some kind of relations it is unable to give the complexity.

For the above examples, the Master theorem cannot be used.

That is all about Master Theorem for finding the time complexity of the algorithms.

References :

“Introduction to Algorithm” by Thomas H Cormen, Charles E Leiserson, Ronald L Rivest, Clifford Stein.

Add a comment

Related posts:

Almohada Embarazo

Si eres de las que pasan por la etapa del embarazo, considérate la mujer más afortunada del mundo, porque pronto vas a ser madre y tendrás a un pedazito de cielo con quien compartir la vida y todos…

Nikon Digital SLR Camera

Nikon is the most popular camera brand in the world. They produce some of the best DSLR cameras on the market, and they are constantly innovating with new technologies to make their products better…

Stop blaming the media

Over the last several years, “the media” has become a large target of many to vent their anger and frustration. I have even heard some go as far as to say that they think someone (such as the…