Skip to content

Spruce - Zandra#26

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

Spruce - Zandra#26
zandra2 wants to merge 1 commit intoAda-C16:masterfrom
zandra2:master

Conversation

@zandra2
Copy link

@zandra2 zandra2 commented Jun 21, 2022

Heaps Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
How is a Heap different from a Binary Search Tree? Heaps are unordered
Could you build a heap with linked nodes? No
Why is adding a node to a heap an O(log n) operation? Because you only need to iterate half of the tree
Were the heap_up & heap_down methods useful? Why? Yes. heap_up checks if a node needs to move up and swap when necessary. heap_down removes a node at the root and replace the respective child upward.

@zandra2 zandra2 changed the title getting ready for PR Spruce - Zandra Jun 21, 2022
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.

✨💫 Excellent implementation!
For the comprehension questions:
How is a Heap different from a Binary Search Tree? --> You answered that heaps are unordered. Heaps are _semi_ordered. Parents must be bigger/smaller (depending on whether it's a max/min heap) than each of their children.

Could you build a heap with linked nodes? --> You said no. It is possible, but it's not the most efficient way to implement it because of all the insertion/deletion and tracking parents/children.

Let me know what questions you have.

🟢

""" This method uses a heap to sort an array.
Time Complexity: ?
Space Complexity: ?
Time Complexity: O(n log n)?

Choose a reason for hiding this comment

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

Comment on lines +22 to +23
Time Complexity: O(log n)?
Space Complexity: O(log n)? (the recursive stack space, if done iteratively it's constant space)

Choose a reason for hiding this comment

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

💫 Very nice! Most folks don't catch the space complexity there.

maintaining the heap structure
Time Complexity: ?
Space Complexity: ?
Time Complexity: O(log n)?

Choose a reason for hiding this comment

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

""" This method returns true if the heap is empty
Time complexity: ?
Space complexity: ?
Time complexity: constant ?

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: O(log n) ?
Space complexity: O(log n) ?

Choose a reason for hiding this comment

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

moves the corresponding element down the heap if it's
larger than either of its children and continues until
the heap property is reestablished.
"""

Choose a reason for hiding this comment

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

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