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

Richelle ~~ water ~~ binary search tree #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

r-spiel
Copy link

@r-spiel r-spiel commented Apr 12, 2021

Sorry I think I must have cloned the base repo initially instead of forking it, well here is my submission now. Thanks! -Richelle

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 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) {

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) {

Choose a reason for hiding this comment

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

👍 Nice looping solution

Comment on lines +84 to +87
// Time Complexity: O(n)
// Space Complexity: O(n)
// preorder: current, left, right (parent nodes get pushed to list first)
preorderHelper(current, array) {

Choose a reason for hiding this comment

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

👍

Comment on lines +67 to +70
// 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) {

Choose a reason for hiding this comment

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

👍

Comment on lines +119 to +121
// Time Complexity: O(n) - touches every node
// Space Complexity: O(log(n)) - for the call stack?
height(current=this.root, count=0) {

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.

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