Skip to content

Symone B.#23

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

Symone B.#23
syblades wants to merge 1 commit intoAda-C16:masterfrom
syblades:master

Conversation

@syblades
Copy link

Heaps Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer

How is a Heap different from a Binary Search Tree?

  • A BST is an ordered data structure that is more efficient when searching (everything not only min and max) whereas a Heap is better used for finding the max or min given the structures of max_heap and min_heap.

Could you build a heap with linked nodes?

  • You can build a heap with linked nodes, although, they are typically built using an array as the underlying data structure.

Why is adding a node to a heap an O(log n) operation?

  • Adding a node to a heap is an O(log n) operation (worst-case) because we need to swap a node at each level of the Binary Tree. A full Binary Tree has O(log n) levels with n being the number of nodes.

Were the heap_up & heap_down methods useful? Why?

  • Both the heap_up and heap_down methods were useful because it increased my comprehension of how the swaps take place based on the value of the element.

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.

💫🤠 Very nice work Symone. I left some comments on space complexity below. Let me know what questions you have.

🟢

Time Complexity: ?
Space Complexity: ?
Time Complexity: O(n log n)
Space Complexity: O(n)

Choose a reason for hiding this comment

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

self.store = []

# helpers
def parent_index(self, index):

Choose a reason for hiding this comment

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

💖 Love these!

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

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

Choose a reason for hiding this comment

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

💫 Very concise

the heap property is reestablished.
"""
pass

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(1)

Choose a reason for hiding this comment

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

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

Time complexity: ?
Space complexity: ?
Time complexity: O(1)
Space complexity: O(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: O(log n)
Space Complexity: O(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_down space complexity is O(log n)

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

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