Skip to content

Conversation

@goblineer
Copy link

Heaps Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
How is a Heap different from a Binary Search Tree? Heaps are more efficient to build in the real world, as all BSTs worth their salt are self-balancing and creating them is, therefore, O(_n_Log(n) in time complexity (and requires extra space for pointers and for balancing markers eg, redness/blackness). That said, since a BST is laterally consistent, there's a bunch of extremely common use cases in which BST is a better bet (printing out all the nodes in sorted order is one example).
Could you build a heap with linked nodes? Sure, but don't. Comparisons are cheaper with integer keys.
Why is adding a node to a heap an O(log n) operation? Because it relies on the heap_up function to tidy up after the insertion.
Were the heap_up & heap_down methods useful? Why? It would be a freaking disaster to implement a heap without sifting. Maybe if you got extremely lucky, your array would already be in the right order and ... no, honestly, I still can't figure that out. There is literally no way to create a heap without shifting. That's the whole point of heaps.

Copy link

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kate! It's good to hear from you... sort of. Not bad, but see my comments on Heapsort & the time /space complexities of your Heap methods.

Let me know if you have questions.

@goblineer
Copy link
Author

Updated to reflect code review comments, corrected space complexity error.

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.

2 participants