Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| courses:cs211:winter2018:journals:donohuem:chapter5 [2018/03/12 21:00] – donohuem | courses:cs211:winter2018:journals:donohuem:chapter5 [2018/03/12 21:39] (current) – [5.3 Counting Inversions] donohuem | ||
|---|---|---|---|
| Line 8: | Line 8: | ||
| ===== 5.2 Recurrence Relations ===== | ===== 5.2 Recurrence Relations ===== | ||
| + | There are various other recurrence relations that correspond to different Divide and Conquer algorithms. For instance, Mergesort divides its input into q=2 subproblems of n/2 size, but other algorithms can have q>2 subproblems. Such a recurrence relationship would look like qT(n/2) + cn (or O(n)). //Question: What is the difference between writing O(n) or cn in the recurrence relationship?// | ||
| ===== 5.3 Counting Inversions ===== | ===== 5.3 Counting Inversions ===== | ||
| + | The motivation of the problem is preference rankings. Suppose we wish to create an algorithm that compares the rankings of one individual to another' | ||
| + | |||
| + | Sort-and-Count(L) | ||
| + | if list L has one element | ||
| + | return 0 and the list L | ||
| + | | ||
| + | (iA, A) = Sort-and-Count(A) | ||
| + | (iB, B) = Sort-and-Count(B) | ||
| + | (i, L) = Merge-and-Count(A, | ||
| + | | ||
| + | | ||
| + | | ||
| + | Overall, the readability of this section is 7/10. | ||
