CST370 - Week 4
CST370 Week 4
This week is a short week due to midterms. We learned about merge sort, which uses the divide-and-conquer method. Merge sort goes through these steps:
- Split the original array into two halves, until each individual element is by itself.
- Sort the first half recursively
- Sort the second half recursively
- Merge the two halves together:
- Compare the first elements of each half
- Push smaller element to a new result array
- Increment index of half that pushed the smaller element
- (Repeat Steps 1-3 until all elements are sorted)
For Master Theorem, the time complexity of merge sort is θ [n*log(n)]. There are two recursive calls, so a = 2, the input size divides by 2 each time, so b = 2, and since the number of comparisons is n, (n^d) = (n^1) => d = 1.
I wanted to understand how to derive the Master Theorem from pseudocode, so I looked up some practice exercises online, but there is very little found for it. I decided to get the textbook because I need more exercises to understand the concepts presented in class.
Comments
Post a Comment