Example: Suppose you have to choose among three algorithms to

Example: Suppose you have to choose among three algorithms to solve a problem:
β€’
β€’
β€’
Algorithm A solves an instance of size 𝑛 by recursively solving eight instances of
!
size ! , and then combining their solutions in time Ο(𝑛! ).
Algorithm B solves an instance of size 𝑛 by recursively solving twenty instances
!
of size ! , and then combining their solutions in time Ο(𝑛! ).
Algorithm C solves an instance of size 𝑛 by recursively solving two instances of
size 2𝑛, and then combining their solutions in time Ο(𝑛).
Which one is preferable and why?
Solution:
β€’
Algorithm A:
𝑇 𝑛 = 8𝑇
!
!
+ 𝑛!
!
!
π‘Ž = 8; 𝑏 = 2; 𝑛!"#! = 𝑛!"#! = 𝑛!
!
𝑓 𝑛 = 𝑛! β†’ 𝑓 𝑛 = Θ 𝑛!"#! = Θ 𝑛!
𝑇 𝑛 = Θ(𝑛! 𝑙𝑔𝑛)
β€’
Algorithm B:
𝑇 𝑛 = 20𝑇
!
+ 𝑛!
!
!
!"
π‘Ž = 20; 𝑏 = 3; 𝑛!"#! = 𝑛!"#! = 𝑛!.!"
!
𝑓 𝑛 = 𝑛! β†’ 𝑓 𝑛 = Ξ© 𝑛!"#! !! = Ξ© 𝑛!.!"!!
!"
𝑇 𝑛 = Θ 𝑛!"#!
β€’
πΆπ‘Žπ‘ π‘’ 2 π‘œπ‘“ π‘€π‘Žπ‘ π‘‘π‘’π‘Ÿ π‘€π‘’π‘‘β„Žπ‘œπ‘‘
= Θ(𝑛!.!" )
Algorithm C:
𝑇 𝑛 = 2𝑇 2𝑛 + 𝑛
The running time of this algorithm is β€œinfinite”
Algorithm B is the preferable.
πΆπ‘Žπ‘ π‘’ 3 π‘œπ‘“ π‘€π‘Žπ‘ π‘‘π‘’π‘Ÿ π‘€π‘’π‘‘β„Žπ‘œπ‘‘
π‘“π‘œπ‘Ÿ 0 β‰Ί πœ€ β‰Ό 0.73