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
Copy Markdown

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
Copy Markdown

@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.

🟢

Comment thread heaps/heap_sort.py
Time Complexity: ?
Space Complexity: ?
Time Complexity: O(n log n)
Space Complexity: O(n)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment thread heaps/min_heap.py
self.store = []

# helpers
def parent_index(self, index):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💖 Love these!

Comment thread heaps/min_heap.py
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]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💫 Very concise

Comment thread heaps/min_heap.py
the heap property is reestablished.
"""
pass

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comment thread heaps/min_heap.py
Time complexity: ?
Space complexity: ?
Time complexity: O(log n)
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.

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

Comment thread heaps/min_heap.py
Time complexity: ?
Space complexity: ?
Time complexity: O(1)
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.

Comment thread heaps/min_heap.py
Time Complexity: ?
Space Complexity: ?
Time Complexity: O(log n)
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.

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

Comment thread heaps/min_heap.py
Time Complexity: ?
Space Complexity: ?
Time Complexity: O(log n)
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.

✨ 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