How do you analyze time complexity of recursive algorithms?
LeetCode Patterns Flashcards: Tries, Design Problems, LRU Cache, Time Complexity
Аудио-карточка · 0:26Nortren·
How do you analyze time complexity of recursive algorithms?
0:26
For recursive algorithms, count the number of recursive calls and the work done per call. If each call makes two recursive calls and does O of one work, the total is O of two to the power of n. Draw the recursion tree: the total work is the sum across all levels. For divide-and-conquer, the Master Theorem provides formulas based on the recurrence relation: if T of n equals a times T of n over b plus O of n to the d, the complexity depends on how log base b of a compares to d.
neetcode.io