Skip to content

Conversation

@tatsqui
Copy link

@tatsqui tatsqui commented Sep 6, 2019

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, I like how you worked through breadth first search. You made good use of helper methods and did a good job with the Big-O. I also like the tests you wrote.

# Time Complexity:
# Space Complexity:
def bst_preorder(node, arr)
if !node

Choose a reason for hiding this comment

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

So if node is nil, you try to add the key & value to the list?


# Time Complexity:
# Space Complexity:
# Time Complexity: O(log n) - omit half of dataset to add a value if tree is balanced

Choose a reason for hiding this comment

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

And O(n) if the tree is not balanced.

# Time Complexity:
# Space Complexity:
# Time Complexity: O(n) because we visit each node once
# Space Complexity: O(h) where h is equal to height of tree unless tree is imbalanced, then O(n)

Choose a reason for hiding this comment

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

👍

return breadth_first(node, array)
end

def breadth_first(node, arr)

Choose a reason for hiding this comment

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

Nice!

# Useful for printing
def to_s
return "#{self.inorder}"
puts "#{self.inorder}"

Choose a reason for hiding this comment

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

Just a note, you can't test something being printed, it's easier to test a string result.

Plus you can always do: puts my_tree.to_s

end
end

describe "bst height" do
Copy link

@CheezItMan CheezItMan Sep 10, 2019

Choose a reason for hiding this comment

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

👍 BTW I'm going to swipe these for C12

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