algoPhobic
New member
- Joined
- Jan 17, 2017
- Messages
- 15
Hello,
In Harvard's CS50 open courseware lecture, the running time of the Bubble Sort algorithm is analyzed. The input instance being discussed, is an 8-element-long array.
At the 42:54 mark in the video lecture, the prof professes...
Imagine my surprise when I learned that the following solution — which I would have guessed for the above equation (where n = 8)...
...is dead wrong.
Am I correct is guessing that the idea|rule|law behind the prof's n2/2 - n/2 solution has something to do with recurrences?
Please, can anybody advise on what I need to study in order to grok the n2/2 - n/2 solution? As in, links to learning resources? Tutorials? Recommended reading, etc?
Thanks in advance.
In Harvard's CS50 open courseware lecture, the running time of the Bubble Sort algorithm is analyzed. The input instance being discussed, is an 8-element-long array.
At the 42:54 mark in the video lecture, the prof professes...
Code:
(n - 1) + (n - 2) + ... + 1
= n(n -1)/2
= (n[SUP]2[/SUP] - n)/2
= n[SUP]2[/SUP]/2 - n/2
Imagine my surprise when I learned that the following solution — which I would have guessed for the above equation (where n = 8)...
Code:
= (n + n + n + n + n + n + n) + (-1 + -2 + -3 + -4 + -5 + -6 + -7 + 1)
= 7n + -27
...is dead wrong.
Am I correct is guessing that the idea|rule|law behind the prof's n2/2 - n/2 solution has something to do with recurrences?
Please, can anybody advise on what I need to study in order to grok the n2/2 - n/2 solution? As in, links to learning resources? Tutorials? Recommended reading, etc?
Thanks in advance.