Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Heaps Practice
Congratulations! You're submitting your assignment!
Comprehension Questions
Could you build a heap with linked nodes? | You can, however, it's easier to build with an array.
Why is adding a node to a heap an O(log n) operation? | Adding has a time complexity of O(1) so long as you're adding to the end of the array. If you need to heap_up to insert the added value at a level above the end of the array, each heap_up will be O(log n) because one swap occurs per level and there are log n levels.
Were the
heap_up&heap_downmethods useful? Why? | Yes. Heap_up was necessary to insert values that fit closer to the bottom of the heap. Heap_down was necessary for the opposite reason (if a value needs to be placed closer to the top of the heap, it's more efficient to heap from the top down). Unless you're only adding values to the end of the heap, you need heap_up and heap_down in order to insert values in numerical order to maintain the proper structure for the heap.