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

Ports - Jillianne #28

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

Ports - Jillianne #28

wants to merge 6 commits into from

Conversation

jillirami
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.

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)

Choose a reason for hiding this comment

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

Nice iterative solution!

Comment on lines +139 to 164
# 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

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!

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