-
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
Ports - Jillianne #28
base: master
Are you sure you want to change the base?
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.
Really nice work, you hit all the learning goals here. Well done!
# Time Complexity: | ||
# Space Complexity: | ||
# Time Complexity: O(log n) - side eliminated | ||
# Space Complexity: O(1) | ||
def add(key, value) |
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 iterative solution!
# Time Complexity: O(n) - all nodes visited | ||
# Space Complexity: O(n) - array size based on size of tree | ||
def bfs | ||
raise NotImplementedError | ||
return [] if !@root | ||
|
||
values = [{key: @root.key, value: @root.value}] | ||
bfs_helper(@root, values) | ||
end | ||
|
||
def bfs_helper(current, array) | ||
if current.left | ||
array << {key: current.left.key, value: current.left.value} | ||
end | ||
if current.right | ||
array << {key: current.right.key, value: current.right.value} | ||
end | ||
if !current.left && !current.right | ||
return array | ||
end | ||
if current.left | ||
bfs_helper(current.left, array) | ||
end | ||
if current.right | ||
bfs_helper(current.right, array) | ||
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.
Really nice work on this. This may help you with the Graph unit!
No description provided.