Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pine - Kristel J #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Pine - Kristel J #15

wants to merge 1 commit into from

Conversation

KJabbusch
Copy link

Heaps Practice

Congratulations! You're submitting your assignment!

Comprehension Questions

Question Answer
How is a Heap different from a Binary Search Tree?
Could you build a heap with linked nodes?
Why is adding a node to a heap an O(log n) operation?
Were the heap_up & heap_down methods useful? Why?

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 Kristel, however there are a few issues with your heap_sort function and time complexity. Also, you left the comprehension questions blank. I'm grading this as a yellow, but please feel free to resubmit if you would like a green score! 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.

👀 Time and space complexity and overall logic flow are correct, however, your heap_sort tests are failing. See my comment below!

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.

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

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.

✨ Very nice, however like above, the space complexity is O(log n) because of the recursive call stack of heap_down

def __str__(self):
""" This method lets you print the heap, when you're testing your app.
"""
if len(self.store) == 0:
return "[]"
return f"[{', '.join([str(element) for element in self.store])}]"


def empty(self):

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 space complexity is O(log n) because of the recursive call stack

store = self.store
if store[parent].key > store[index].key:
self.swap(parent, index)
self.heap_up(parent)

def heap_down(self, index):

Choose a reason for hiding this comment

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

✨ Very nice!


for item in list:
heap = heap.add(item)

Choose a reason for hiding this comment

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

Your failing tests for heap_sort return AttributeError: 'NoneType' object has no attribute 'add'. Look at the return value for add and see if you can figure out why that might be 🤔

What are you setting the heap equal to here? Do you need to be?

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