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

Spruce - Angela Fan #56

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

Spruce - Angela Fan #56

wants to merge 1 commit into from

Conversation

fan-gela
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.

✨🌟 Nice work, Angela. I left some comments on time and space complexity as well as how you might rework your BFS implementation. Let me know what questions you have.

🟢

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

Choose a reason for hiding this comment

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

🪐 Space complexity will be O(1) here because you aren't creating a call stack or any new data structures that vary with the size of the input (the size of your tree)

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

Choose a reason for hiding this comment

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

🪐⬆️ Same thing as add with the space complexity here



# Time Complexity: O(n)
# Space Complexity: O(n)
def inorder(self):

Choose a reason for hiding this comment

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

self.preorder_helper(current_node.right, items)

# Time Complexity: O(log n)
# Space Complexity: O(log n)
def preorder(self):

Choose a reason for hiding this comment

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



# Time Complexity: O(log n)
# Space Complexity: O(log n)
def postorder(self):

Choose a reason for hiding this comment

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

⏱🪐 This is going to be O(n) space complexity like preorder and inorder because you are creating a list of all n nodes in the tree and to do that you are creating a recursive call for each of the n nodes.

Comment on lines +123 to +124
# Time Complexity: O(log n)
# Space Complexity: O(log 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 is going to be O(log n) because you recursively call height_helper on each node in the list.

# # Time Complexity:
# # 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.

With breadth first search you want to traverse the tree starting from its root, then visit each of it's children (from left to right), before visiting the children's children and so forth. In other words, you want to traverse the tree level by level.

With your bfs_helper, you are adding the root node of the current tree, but then your recursive call through the left subtree will finish before you ever look at the root of the right subtree.

(Hint: this may be easier to think about iteratively)

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