Skip to content

Conversation

@shubha-rajan
Copy link

Heaps Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
How is a Heap different from a Binary Search Tree? Binary search trees are sorted in a way that the value of the left child of a node will always be less than the node value, and the right child value will always be greater. With a heap, the sorting guarantee is that a node value will always be less than (in a min heap) or greater than (in a max heap) its child node values
Could you build a heap with linked nodes? Yes, you can build a heap with HeapNode objects that point to their left and right children, or you can represent a heap as an array.
Why is adding a node to a heap an O(log n) operation? You need to perform the heap_up operation up to log n times to put the new node in the correct position.
Were the heap_up & heap_down methods useful? Why? They were useful in order to keep the heap structure intact when adding and removing elements

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.

Nice work, I love the O(1) heapsort. See my notes on space complexity for the heap methods. Well done.

# Space Complexity: ?
def heap_sort(list)
raise NotImplementedError, "Method not implemented yet..."
def heapsort(list)

Choose a reason for hiding this comment

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

Really nice work building an O(1) space complexity heapsort.

# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: O (log n) where n is the number of nodes in the store
# Space Complexity: O(1)

Choose a reason for hiding this comment

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

Since heap_up is recursive, you have some space complexity here. This should also be O(log n)

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