Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| courses:cs211:winter2018:journals:shermanc:chapter5 [2018/03/21 03:32] – [5.1: A First Recurrence: The Mergesort Algorithm] shermanc | courses:cs211:winter2018:journals:shermanc:chapter5 [2018/03/21 07:12] (current) – shermanc | ||
|---|---|---|---|
| Line 6: | Line 6: | ||
| ===== 5.1: A First Recurrence: The Mergesort Algorithm ===== | ===== 5.1: A First Recurrence: The Mergesort Algorithm ===== | ||
| - | This section will discuss Mergesort and the motivations and workings behind it. Mergesort works by dividing the problem into two parts and then solving each, combining each solution at the end. It will take us O(n) time to divide the problem into two, where we will break it down until there is sets of size 2. Then it spends T(n/2) time solving them and finally O(n) to combine everything back into one. So, T(n) is the runtime for the runtime relation. | + | This section will discuss Mergesort and the motivations and workings behind it. Mergesort works by dividing the problem into two parts and then solving each, combining each solution at the end. It will take us **O(n)** time to divide the problem into two, where we will break it down until there is sets of size 2. Then it spends |
| + | |||
| + | There are two ways that we can solve recurrences. | ||
| + | |||
| + | Overall, this section was pretty simple and made sense. | ||
| + | |||
| + | |||
| + | ===== 5.2: Further Recurrence Relations ===== | ||
| + | |||
| + | Looking at problems that have //q// > 2 subproblems, | ||
| + | |||
| + | This section was rather short and the information it held was rather simple. | ||
| + | |||
| + | |||
| + | ===== 5.3: Counting Inversions ===== | ||
| + | |||
| + | This sections main topic was of the use of " | ||
| + | |||
| + | Merge-and-Count will start with a pointer to the front of each list. We will keep track of a count as well. To start, while both lists are not empty, we look at the elements that have the pointers, then append the smaller of the two to our output list. If this element came from list B, we will increment our count by that of the number of remaining elements in list A. This will continue until one list is empty. | ||
| + | |||
| + | Sort-and-Count uses Merge-and-Count inside of it. It first checks to make sure the list is greater than 1 and if so, it divides the list into two, running Sort-and-Count on each and then finally running Merge-and-Sort at the end. Therefore, the running time of **T(n)** satisfies the recurrence | ||
| + | |||
| + | This section was actually pretty interesting, | ||
