Skip to content

Spruce- Rebecca Z#22

Open
rzuick wants to merge 1 commit intoAda-C16:masterfrom
rzuick:master
Open

Spruce- Rebecca Z#22
rzuick wants to merge 1 commit intoAda-C16:masterfrom
rzuick:master

Conversation

@rzuick
Copy link

@rzuick rzuick commented May 18, 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 is unordered
Could you build a heap with linked nodes? Probably. Since a heap under the hood is essentially an array, and a linked list is a special type of array, I think you could.
Why is adding a node to a heap an O(log n) operation? Because you end up searching through half of the tree to find the index to add the node
Were the heap_up & heap_down methods useful? Why? Yes. Recursion.

Copy link

@kyra-patton kyra-patton 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 left some comments on complexity below. Let me know what questions you have.

🟢

larger than either of its children and continues until
the heap property is reestablished.
Time Complexity: Ologn
Space Complexity: O1

Choose a reason for hiding this comment

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

✨ Space complexity is O(log n) here because of the recursive call stack

Time complexity: ?
Space complexity: ?
Time complexity: Ologn
Space complexity: O1

Choose a reason for hiding this comment

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

✨ Because of the recursive call stack, space complexity is O(log n)

Time complexity: ?
Space complexity: ?
Time complexity: O1
Space complexity: 01

Choose a reason for hiding this comment

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

Time Complexity: ?
Space Complexity: ?
Time Complexity: Ologn
Space Complexity: O1

Choose a reason for hiding this comment

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

✨ Because of the recursive call stack of heap_down, space complexity is O(log n)

Time Complexity: ?
Space Complexity: ?
Time Complexity: Ologn
Space Complexity: On

Choose a reason for hiding this comment

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

✨ The space complexity here is determined by the recursive call stack of heap_up which is just O(log n)

Time Complexity: ?
Space Complexity: ?
Time Complexity: On
Space Complexity: On

Choose a reason for hiding this comment

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

✨ Time complexity here will be O(n log n) where n is length of list. For each of n items in list, you perform heap.add()/heap.remove() which are both log n operations.

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