Skip to content

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!

# 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