This was our fourth week in CST 370 - Design and Analysis of Algorithms.
Merge Sort
This week we discussed Merge Sort. Mergse Sort is a divide-and-conquer algorithm that sorts an array by dividing into two smaller arrays, sorting those two arrays recursively, and recombining (or merging) the arrays back together.


We also briefly discussed the time efficiency of the Merge Sort algorithm:
- Recurrence Relation: T(n) = 2*T(n/2) + n-1 => 2*T(n/2) + Θ(n)
- Using Master Theorem: a = 2, b = 2, d = 1
- Case 2: a = b^d = 2 => Θ(n log n)
Merge Sort Exercise
We also had an exercise to use Merge Sort on an array of numbers:
We first split this array into two halves:
We continue splitting the arrays:
- [5, 3, 1, 9] => [5, 3] [1, 9] => [5] [3] [1] [9]
- [8, 2, 4, 7] => [8, 2] [4, 7] => [8] [2] [4] [7]
Then we merge the arrays, sorting as we go:
- [5] [3] [1] [9] => [3, 5] [1, 9] => [1, 3, 5, 9]
- [8] [2] [4] [7] => [2, 8] [4, 7] => [2, 4, 7, 8]
Then we merge the two halves:
- [1, 3, 5, 9] [2, 4, 7, 8] => [1, 2, 3, 4, 5, 7, 8, 9]
Midterm Practice
This week we will be having our midterm (covering weeks 0-4). Using the topics listed on the midterm review, I made notes of the different definitions, problems, and algorithms that we have covered so far in the course.
Comments
Post a Comment