Skip to content

Conversation

raisahv
Copy link

@raisahv raisahv commented Feb 26, 2020

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, you have the essential methods working well. You also made progress trying BST and delete, although they're not working. Well done

Comment on lines +19 to 21
# Time Complexity: O(logn), at worst, the algorighm will be called O(logn) times to add the new node to the bottom of the tree.
# Space Complexity: O(1) the amount of data stored is constant, though the space required in memory for the stack trace will be O(logn)
def add(key, value)

Choose a reason for hiding this comment

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

👍

Comment on lines +43 to 45
# Time Complexity: O(logn), at worst, the algorighm will be called O(logn) times to add the new node to the bottom of the tree.
# Space Complexity: O(1) the amount of data stored is constant, though the space required in memory for the stack trace will be O(logn)
def find(key)

Choose a reason for hiding this comment

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

👍

Comment on lines +65 to 67
# Time Complexity: O(n), because the algorithm will have to visit every node on the tree to add them to the nodes_array list
# Space Complexity: O(n) because the size of the nodes_array list will vary linearly with the number of nodes in the tree.
def inorder

Choose a reason for hiding this comment

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

👍

Comment on lines +81 to 83
# Time Complexity: O(n), because the algorithm will have to visit every node on the tree to add them to the nodes_array list
# Space Complexity: O(n) because the size of the nodes_array list will vary linearly with the number of nodes in the tree.
def preorder

Choose a reason for hiding this comment

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

👍

Comment on lines +97 to 99
# Time Complexity: O(n), because the algorithm will have to visit every node on the tree to add them to the nodes_array list
# Space Complexity: O(n) because the size of the nodes_array list will vary linearly with the number of nodes in the tree.
def postorder

Choose a reason for hiding this comment

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

👍

Comment on lines +113 to 115
# Time Complexity: O(n), because the algorithm will have to visit every node on the tree in order to determine the height of the tree
# Space Complexity: O(1) because the amount of data stored is constant, though the space required in memory for the stack trace will be O(n)
def height

Choose a reason for hiding this comment

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

⚠️ Since this method is recursive, you have to account for the call stack in terms of space complexity.

Comment on lines +131 to 133
# Time Complexity: O(n), because the algorithm will have to visit every node on the tree to add them to the nodes_array list
# Space Complexity: O(n) because the size of the nodes_array list will vary linearly with the number of nodes in the tree.
def bfs

Choose a reason for hiding this comment

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

Unfortunately this is more like a preorder traversal, this is because you traverse the entire left subtree before you traverse the right subtree. Remember all nodes at level 2 should be next to each other in the array and level 3 etc.

Comment on lines +156 to +157
# couldn't get this to work in time :(
def delete(key)

Choose a reason for hiding this comment

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

It's hard.

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