Skip to content

Ainur-Pine C16 #46

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Ainur-Pine C16 #46

wants to merge 5 commits into from

Conversation

adjayanbaeva
Copy link

No description provided.

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 work, Ainur. All the test cases that were failing were just due to a missing else statement. We can discuss any questions you may have in our next session.

🟢

# Time Complexity:
# Space Complexity:
# BST is not empty
self.insert_node_helper(self.root, key, value)

Choose a reason for hiding this comment

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

Without the else you add the root twice to the list. The tests for add don't fully cover this case, but it reveals itself with the remaining functions where you print out the tree or try and find the height because there's an extra node in the tree. Making this change should allow you to pass all the tests.

Suggested change
self.insert_node_helper(self.root, key, value)
else:
self.insert_node_helper(self.root, key, value)

# Time Complexity:
# Space Complexity:
# Time Complexity: O(log N) or O(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.

Space complexity would be same as time complexity based on the recursive call stack: O(log n) for balanced trees and O(n) for unbalanced trees.



# Time Complexity: O(log N) or O(n)
# Space Complexity: O(n)
def find(self, key):

Choose a reason for hiding this comment

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

✨ However space complexity would be O(1) here since you did this iteratively and aren't creating any additional data structures whose size is proportional to the size of the tree.

# Space Complexity:
# Time Complexity: O(n)
# Space Complexity: O(n)
def inorder_helper(self, current, result):

Choose a reason for hiding this comment

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

# Space Complexity:
# Time Complexity: O(n)
# Space Complexity: O(n)
def preorder_helper(self, current, result):

Choose a reason for hiding this comment

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


# Time Complexity: O(n)
# Space Complexity: O(n)
def postorder_helper(self, current, result):

Choose a reason for hiding this comment

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

# Space Complexity:
# Time Complexity: O(n)
# Space Complexity: O(1)
def height_helper(self, current):

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, space complexity would also be O(n) here

# # Space Complexity:
# # Time Complexity: O(n)
# # Space Complexity: O(n)

def bfs(self):

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