Skip to content

Sarah - #4

Open
sjscotton wants to merge 1 commit into
Ada-C11:masterfrom
sjscotton:master
Open

Sarah#4
sjscotton wants to merge 1 commit into
Ada-C11:masterfrom
sjscotton:master

Conversation

@sjscotton

Copy link
Copy Markdown

No description provided.

@CheezItMan CheezItMan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice work, you hit the learning goals, but take a look at the Big-O for space complexity. You're a little off there.

Comment thread lib/tree.rb
# Time Complexity:
# Space Complexity:
# Time Complexity: O(n) where n is the number of nodes. The inorder recurssive method is called once for each node, and the time complexity for each frame is constant.
# Space Complexity: Worst Case would be O(n^2) for a completely unbalanced tree, becuase you could have n stack frames and n arrays. Best case for a balances tree would be O(log n)^2 because you would have log n stack frames at once and log n arrays at once.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

O(n2)??? You are building an array of each key-value pair, and have the system stack being called on each node, but they're not nested. Remember arrays are passed by reference.

Comment thread lib/tree.rb
return height_recurssive(node, 1, 1)
end

def height_recurssive(curr_node, curr_height, max_height)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nice tail recursive method.

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