Skip to content

Shirley - #2

Open
shirley1chu wants to merge 4 commits into
Ada-C11:masterfrom
shirley1chu:master
Open

Shirley #2
shirley1chu wants to merge 4 commits into
Ada-C11:masterfrom
shirley1chu:master

Conversation

@shirley1chu

Copy link
Copy Markdown

Heaps Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
How is a Heap different from a Binary Search Tree? The keys are in semi-order instead of complete order. Child node keys are either all less, or all greater than the parent. BST has the left side as less, right side as greater.
Could you build a heap with linked nodes? Yes, though it's easier to do it in an array structure.
Why is adding a node to a heap an O(log n) operation? It only needs to traverse one side of the tree (whichever side it got added on based on index)
Were the heap_up & heap_down methods useful? Why? Heap up is useful for adding, because once a new node is added, it needs to be placed in the right position (since it gets added at the end of the heap). Heap down is good for removing elements, because the heap needs to reorder itself once the root element is removed.

@CheezItMan CheezItMan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice work! You hit the learning goals here. Well done!

Comment thread lib/heap_sort.rb
raise NotImplementedError, "Method not implemented yet..."
end No newline at end of file
# Time Complexity: O(nlogn)
# Space Complexity: O(1)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since you are making a new heap and adding all the elements, this is O(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