ADA 3.2: Recursion-Tree Method
Textbook Chapter 4.4 - The recursion-tree method for solving recurrences
Review
Merge Sort
之前ADA 2.4有用過 (Merge Sort)
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
* T(n): 處理size為N所耗費的時間
Recursion-Tree Method 遞迴樹法
Solving recurrence
- Substitution method(取代法)
- Recursion-Tree method(遞迴樹法)
- Master method(套公式大法/大師法)
Steps to solve
- Expand a recurrence into a tree (把樹給展開)
- Sum up the cost of all nodes as a good guess (加總)
- Verify the guess as in substitution method (驗證)
Advantages
- Promote intuition
- Generate good guesses for the subtitution method
=> 比較直覺, 容易猜
Recursion-Tree Example
舉例
(Merge Sort)
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
每層都是cn, 故只要求出樹高就知道總和
總和則為
tree height
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →
累加後為
當子問題足夠小時(切割次數趨近無限), 可以以O(1)秒解掉
就可以忽略
簡單證明
當 時
Image Not Showing
Possible Reasons
- The image file may be corrupted
- The server hosting the image is unavailable
- The image path is incorrect
- The image format is not supported
Learn More →