-
Notifications
You must be signed in to change notification settings - Fork 44
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
Fire - Roshni #30
base: master
Are you sure you want to change the base?
Fire - Roshni #30
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work Roshni, you hit the learning goals here. Well done.
# Time Complexity: O(log n) for balanced, O(n) for unbalanced | ||
# Space Complexity: O(log n) for balanced, O(n) for unbalanced | ||
def add(key, value = nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
# iterative add helper | ||
# def add_helper(current, key, value) | ||
# added_to_tree = false | ||
|
||
# until added_to_tree | ||
# if key <= current.key | ||
# next_node = current.left | ||
# if next_node.nil? | ||
# new_node = TreeNode.new(key, value) | ||
# current.left = new_node | ||
# added_to_tree = true | ||
# else | ||
# current = current.left | ||
# end | ||
# else | ||
# next_node = current.right | ||
# if next_node.nil? | ||
# new_node = TreeNode.new(key, value) | ||
# current.right = new_node | ||
# added_to_tree = true | ||
# else | ||
# current = current.right | ||
# end | ||
# end | ||
# end | ||
# end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
# Time Complexity: O(log n) for balanced, O(n) for unbalanced | ||
# Space Complexity: O(log n) for balanced, O(n) for unbalanced | ||
def find(key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
# Time Complexity: O(n) to visit all nodes | ||
# Space Complexity: O(n) values array depends on how many nodes there are | ||
def inorder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
# Time Complexity: O(n) to visit all nodes | ||
# Space Complexity: O(n) values array depends on how many nodes there are | ||
def preorder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
# Time Complexity: O(n) to visit all nodes | ||
# Space Complexity: O(n) values array depends on how many nodes there are | ||
def postorder |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
# Time Complexity: O(n) to visit all the nodes | ||
# Space Complexity: O(log n) if balanced, O(n) if unbalanced | ||
def height |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
# Time Complexity: O(n^2) due to use of .shift | ||
# Space Complexity: O(n) | ||
# Solution from class | ||
def bfs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 This should work, and good insight with the .shift
's affect on the time complexity.
No description provided.