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

Nataliia Getlin - Rock - C15 #40

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

Conversation

GetlinN
Copy link

@GetlinN GetlinN commented Nov 28, 2021

No description provided.

Copy link

@CheezItMan CheezItMan 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 Nataliia. You hit the learning goals here. Nice work with BFS. Well done

@@ -1,6 +1,6 @@
# Tree Exercise

In this exercise you will implement, in Ruby, several Tree methods.
In this exercise you will implement, in Python, several Tree methods.

Choose a reason for hiding this comment

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

Whoops

Comment on lines +24 to +27
# Time Complexity: O(log n) for balanced BST, O(n) for unbalanced
# Space Complexity: O(1)

def add_helper(self, current, key, value):

Choose a reason for hiding this comment

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

👍 , however the space complexity is O(log n) if the tree is balanced.

Comment on lines +44 to +47
# Time Complexity: O(log n) for balanced BST, O(n) for unbalanced
# Space Complexity: O(1)

def find_helper(self, current, key):

Choose a reason for hiding this comment

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

👍 However due to the recursive stack, the space complexity is O(log n) for a balanced tree.

Comment on lines +62 to +66
# Time Complexity: O(n), because we visit each node once
# Space Complexity: O(depth of the recursion) or O(h), where h is height
# of the tree -> O(n) in the worst case

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.

👍

Comment on lines +82 to +89
# Time Complexity: ^
# Space Complexity: ^

def preorder_helper(self, current, result):
if current:
result.append(current.to_json())
self.preorder_helper(current.left, result)
self.preorder_helper(current.right, result)

Choose a reason for hiding this comment

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

👍

Comment on lines +99 to +103
# ----------- post-order ----------
# Time Complexity: ^
# Space Complexity: ^

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.

👍 Time/space

Comment on lines +119 to +122
# Time Complexity: O(log n) for balanced, O(n) for unbalanced
# Space Complexity: O(n)

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.

👍

Comment on lines +138 to 141
# # 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