btholt / four-semesters-of-cs-part-two

4 Semesters of Computer in 5 Hours, Part 2!
https://frontendmasters.com/courses/computer-science-2/
Other
89 stars 31 forks source link

Heap Sort #1

Open riggs opened 6 years ago

riggs commented 6 years ago

Your written description doesn't ever actually outline the algorithm for making a max heap in the first place. It does demonstrate the algorithm via example, but trying to reverse-engineer the algorithm from that is difficult.

Also neither your description nor example discusses decreasing the heap size when actually sorting.

PS. In your completed example, the heapSize variable is redundant and literally identical to the for loop iterator. You could also pull out a very simple swapPlaces function to clean things up a tiny bit.

PPS. This was a really fun exercise and definitely helped me learn how heap sort works. (And has renewed my curiosity in understanding smoothsort.)