Class Code: AMC621 Instructor: Huilan Chang
<aside>
Divide-and-conquer approach 分而治之方法 ****involves the following three steps.
🔹 The process of dividing the instances continues until they are so small that a solution is readily obtainable.
</aside>
Sorting 排序(由小到大)
🔹Strategy Three steps:
Example. $n=8$ and $A=[27, 10, 12, 20, 25, 12, 15, 22]$. MERGE-SORT($A$, 0, 7)

🔹Pseudocode
MERGE-SORT($A, p, r$)
▶️Google Colab
MERGE($A, p, q, r$)
🔹Analysis Basic operation: the comparison of an item in $L$ and an item in $R$.
Let $W(n)$ be the number of comparisons in the worst-case when the input size is $n$. Then ✏️ $W(n)=\Theta(n\lg n).$ Why?
<aside>
A sorting algorithm is in-place (原位排序) if it does not use any extra space beyond needed storage.
The mergesort is not in-place, because it uses extra spaces $L$ and $R$.
</aside>