Skip to content

Areeba R - Pine#21

Open
AreebaQ wants to merge 2 commits intoAda-C16:masterfrom
AreebaQ:master
Open

Areeba R - Pine#21
AreebaQ wants to merge 2 commits intoAda-C16:masterfrom
AreebaQ:master

Conversation

@AreebaQ
Copy link

@AreebaQ AreebaQ commented May 15, 2022

Heaps Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
How is a Heap different from a Binary Search Tree? The ordering is different with a BST, values cannot be repeated and any given node's value will be greater than the left child but less than the right. Heaps are more concerned with being balanced and occur as min or max heaps.
Could you build a heap with linked nodes? Yes
Why is adding a node to a heap an O(log n) operation? Because you have to make sure the heap is balanced. This means you may have to shift the nodes around to regain balance
Were the heap_up & heap_down methods useful? Why? Yes because they helped us to add/remove values from the heap where each method only had one individual responsibility and these functions helped us make recursive calls.

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.

💫 Great job Areeba! I left a couple comments on complexity. Let me know what questions you have.

🟢

Time Complexity: ?
Space Complexity: ?
Time Complexity: n log n
Space Complexity: n

Choose a reason for hiding this comment

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

✨ Nice! How might you implement this using the MinHeap you created below?

self.store[index_1] = self.store[index_2]
self.store[index_2] = temp

def parent_idx(self, index):

Choose a reason for hiding this comment

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

💫 Nice helpers!

Comment on lines +102 to +103
left = index * 2 + 1
right = index * 2 + 2

Choose a reason for hiding this comment

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

🤔 Why not use your helpers here?

""" This helper method takes an index and
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.

✨ Great job! Love the comments

Time complexity: ?
Space complexity: ?
Time complexity: log n
Space complexity: 1

Choose a reason for hiding this comment

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

✨ Nice, however because of the recursive call stack, space complexity is O(log n) here

Time complexity: ?
Space complexity: ?
Time complexity: 1
Space complexity: 1

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: log n
Space Complexity: 1

Choose a reason for hiding this comment

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

✨ Nice, however because of the recursive call stack of heap_down, space complexity is also O(log n)

Time Complexity: ?
Space Complexity: ?
Time Complexity: log n
Space Complexity: 1

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_up space complexity is O(log n) here

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