Conversation
CheezItMan
left a comment
There was a problem hiding this comment.
Nice work, you hit the basic learning goals, with some issues on space/time complexity. You also have a height method which isn't working. Check out my comments and let me know if you have any questions.
| # Time Complexity: O(h) where h is the max height of the binary search tree. | ||
| # In a best case scenario, time complexity would be O(logn) | ||
| # Space Complexity: O(1) | ||
| def add(key, value) |
There was a problem hiding this comment.
The space complexity is O(log n) if the tree is balanced and O(n) if it's not.
| # Time Complexity: If tree is balanced, it would be O(logn) n being the size of the tree | ||
| # In a worst case scenario, the time complexity would be O(n) | ||
| # Space Complexity: O(1) | ||
| def find(key) |
There was a problem hiding this comment.
The space complexity is O(log n) if the tree is balanced and O(n) if it's not.
| # Time Complexity: O(h) h is the height of the tree | ||
| # Space Complexity: O(h) h is the height of the tree | ||
| def inorder |
There was a problem hiding this comment.
Since you're visiting each node and creating a list containing all node values... the time/space complexity is O(n).
| # Time Complexity: O(h) h is the height of the tree | ||
| # Space Complexity: O(h) h is the height of the tree | ||
| def preorder |
There was a problem hiding this comment.
Since you're visiting each node and creating a list containing all node values... the time/space complexity is O(n).
| # Time Complexity: O(h) h is the height of the tree | ||
| # Space Complexity: O(h) h is the height of the tree | ||
| def postorder |
There was a problem hiding this comment.
Since you're visiting each node and creating a list containing all node values... the time/space complexity is O(n).
| def height_helper(current_node, max, count) | ||
| return max if current_node.nil? | ||
|
|
||
| if count > max | ||
| max = count | ||
| end | ||
|
|
||
| height_helper(current_node.left, max, count + 1) | ||
| height_helper(current_node.right, max, count + 1) | ||
| end |
There was a problem hiding this comment.
No description provided.