Skip to content

Conversation

@ropeeps
Copy link

@ropeeps ropeeps commented Sep 28, 2022

Heaps Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
How is a Heap different from a Binary Search Tree? A heap has a complete structure. The last level of the tree in a heap is filled from left to right.

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_down methods 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant