# Master Method for Solving Recurrence Relation

The master method works only for following type of recurrences or for recurrences that can be transformed to following type.

T(n) = aT(n/b) + f(n) where a >= 1 and b > 1

There are following three cases: **1.** If f(n) = O(n^{c}) where c < Log_{b}a then T(n) = Θ(n^{Log}_{b}^{a})

**2.** If f(n) = Θ(n^{c}) where c = Log_{b}a then T(n) = Θ(n^{c}Log n)

3 . If 𝑓(𝑛) = 𝑂(𝑛 𝑙𝑜𝑔𝑏 𝑎+∈ )for some ∈> 0 , and if 𝑎𝑓 ( 𝑛 𝑏 ) ≤ 𝑐𝑓(𝑛) for some constant c < 1 𝑎𝑛𝑑 𝑎𝑙𝑙 𝑠𝑢𝑓𝑓𝑖𝑐𝑖𝑒𝑛𝑡𝑙𝑦 𝑙𝑎𝑟𝑔𝑒 𝑛. 𝑇(𝑛) = 𝜃(𝑓(𝑛))

**How does this work?**

Master method is mainly derived from recurrence tree method. If we draw recurrence tree of T(n) = aT(n/b) + f(n), we can see that the work done at root is f(n) and work done at all leaves is Θ(n^{c}) where c is Log_{b}a. And the height of recurrence tree is Log_{b}n

In recurrence tree method, we calculate total work done. If the work done at leaves is polynomially more, then leaves are the dominant part, and our result becomes the work done at leaves (Case 1). If work done at leaves and root is asymptotically same, then our result becomes height multiplied by work done at any level (Case 2). If work done at root is asymptotically more, then our result becomes work done at root (Case 3).

example- In binary search T(n) = T(n/2) + Θ(1). It also falls in case 2 as c is 0 and Log_{b}a is also 0. So the solution is Θ(Logn)

#SolvingRecurrences #Analysis #Algorithm #MasterMethod #Probyto #ProbytoAI

Subscribe and follow us for latest news in Data Science and Machine learning and stay updated!

Facebook: https://facebook.com/probyto

Twitter: https://twitter.com/probyto

LinkedIn: https://linkedin.com/company/probyto

Instagram: https://instagram.com/probyto