@@ -52,10 +52,26 @@ questions in the `Algorithms_Answers.md` file.
5252#### Task 1. Implement Heapsort
5353
5454Inside the ` task1 ` directory you'll find the ` heap.py ` file with a working
55- implementation of the heap class. Your second task is to implement a sorting
56- method called [ heapsort] ( https://en.wikipedia.org/wiki/Heapsort ) that uses the
57- heap data structure in order to sort an array of numbers. Your ` heapsort `
58- function should return a new list containing all of the sorted data.
55+ implementation of the heap class--the heap is already written for you.
56+
57+ You have to figure out how to use the heap to implement heapsort.
58+
59+ Some hints:
60+
61+ * Initially when you make a new ` Heap ` data structure, it is empty.
62+
63+ * You can insert values into the heap with its ` insert() ` method.
64+
65+ * This is a _ max heap_ . That is, the ` get_max() ` and ` delete() ` methods will
66+ return the maximum value stored in the heap. In addition ` delete() ` also
67+ removes the value from the heap.
68+
69+ * Pseudocode in Wikipedia or elsewhere will be of little use here. Think
70+ conceptually at first; how could you use this information to sort a list of
71+ numbers? Then code.
72+
73+ Your ` heapsort ` function should return a new list containing all of the sorted
74+ data.
5975
6076Run ` python test_heap.py ` to run the tests for your ` heapsort ` function to
6177ensure that your implementation is correct.
@@ -65,17 +81,16 @@ ensure that your implementation is correct.
6581Open up the ` Analysis_Answers.md ` file. This is where you'll jot down your
6682answers for the runtimes of the functions you just implemented.
6783
68- ### Stretch Problems
69-
70- #### Min versus Max
84+ ### Stretch Problem: Min versus Max
7185
7286The heap presented in the code is called a _ max heap_ , because ` delete() ` always
7387returns the maximum value in the heap.
7488
7589Modify it to be a _ min heap_ , so that ` delete() ` always returns the _ minimum_
76- value in the heap.
90+ value in the heap. Also change ` get_max() ` to ` get_min() ` .
7791
78- Fix your heapsort after you do this. What did you have to modify?
92+ Your heapsort probably broke after you did this. What did you have to modify to
93+ fix it?
7994
8095How does the time complexity change?
8196
0 commit comments