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

Gloria Scissors - Binary Trees #46

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

Conversation

ggrossvi
Copy link

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.

Well done Gloria. You hit the learning goals here. Nice work.

Comment on lines +21 to 23
# Time Complexity: O(n) because looping through all the nodes
# Space Complexity: O(n) because you need to add a node for each key, value
def add(self, key, value = None):

Choose a reason for hiding this comment

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

👍 The time complexity is O(n log n ) if the tree is balanced and O(n) otherwise.

Comment on lines +42 to +44
def create_dict(self, TreeNode):
return { "key": TreeNode.key,
"value": TreeNode.value }

Choose a reason for hiding this comment

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

Useful helper, maybe put this in the TreeNode class.

Comment on lines +47 to 50
# Time Complexity: log(n) because we are examining only half of the nodes
# Space Complexity: O(1) because we are not allocating any memory
# self refers to object the class is making
def find(self, key):

Choose a reason for hiding this comment

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

👍 The time complexity is O(n log n ) if the tree is balanced and O(n) otherwise.

self.inorder_traverse(node.right, node_list)



def inorder(self):

Choose a reason for hiding this comment

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

👍 Time/space complexity?

Comment on lines +105 to 107
# Time Complexity: 0(N)
# Space Complexity: Space Complexity: 0(N) depends on input size
def preorder(self):

Choose a reason for hiding this comment

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

👍 Time/space complexity?

Comment on lines +117 to 119
# Time Complexity: 0(N)
# Space Complexity: 0(N) depends on input size
def postorder(self):

Choose a reason for hiding this comment

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

👍 Time/space complexity?

Comment on lines +128 to +130
# Time Complexity: 0(1) constant time
# Space Complexity: 0(1)
def height(self):

Choose a reason for hiding this comment

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

👍 this is O(n) for time complexity and O(n) space complexity if the tree is unbalanced and O(log n) if the tree is balanced.

# While que not empty
# Before pop head get info of current node add dict to the final array
# Encue the children insert at the tail
# https://www.geeksforgeeks.org/level-order-tree-traversal/
def bfs(self):

Choose a reason for hiding this comment

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

👍 Nice work!

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