-
Notifications
You must be signed in to change notification settings - Fork 11
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
Richelle ~~ water ~~ binary search tree #5
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.
Nice work Richelle, I like the looping solutions for add and find. I'm unconvinced that your height
function will work in all situations. Other than that this looks good.
// Time Complexity: ? | ||
// Space Complexity: ? | ||
// Time Complexity: O(log(n) assuming the tree is balanced, because it would eliminate half the tree in each loop. If not balanced, then it would be O(n), acting more like a linkedList. | ||
// Space Complexity: O(1) | ||
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 looping solution
// Time Complexity: ? | ||
// Space Complexity: ? | ||
// Time Complexity: O(log(n)) - if a balanced tree, otherwise, O(n) | ||
// Space Complexity: O(1) | ||
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.
👍 Nice looping solution
// Time Complexity: O(n) | ||
// Space Complexity: O(n) | ||
// preorder: current, left, right (parent nodes get pushed to list first) | ||
preorderHelper(current, array) { |
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) - touching every node | ||
// Space Complexity: O(n) - array is length n, and n number of recursive calls on the stack | ||
// inorder: left, current, right (left most nodes get pushed to list first, right last since it's largest) | ||
inorderHelper(current, array) { |
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) - touches every node | ||
// Space Complexity: O(log(n)) - for the call stack? | ||
height(current=this.root, count=0) { |
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.
🤔 I don't see where this is evaluating which is larger the left or right subtree. It seems to just return the count if the left subtree exists.
Sorry I think I must have cloned the base repo initially instead of forking it, well here is my submission now. Thanks! -Richelle