Algorithm Analysis and the Master Theorem
Design a Bad Sort Algorithm
- Goal: Design an inefficient sorting algorithm.
- Consideration: Time complexity.
The Master Theorem
Used to determine the time complexity of algorithms with specific recurrence relations.
General form:
T(n)={kif n=1 aT(bn)+ncif n>1
where a>0, b>1, c≥0, d≥0, k>0
Solutions:
- If logba<c, then T(n)=O(nc)
- If logba=c, then T(n)=O(nclogn)
- If log<em>ba>c, then T(n)=O(nlog</em>ba)
Example:
- Given solution: T(n)=O(nlogn)
- Which can also be expressed as: O(nlogba)
Applying the Master Theorem
- Objective: Use the master theorem to determine the time complexity of algorithms from recurrence relations.