-
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
Aimee 👾 - Fire 🔥 #2
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, you hit the learning goals here Aimee. Well done. I did have one comment on your time complexity for bfs
.
// Time Complexity: Worst case, O(n) (the BST would be a structure similar to a linked list, just a linear chain of values). The BST grows exponentionally with respect to each level, so the total number of levels with respect to the total number of nodes is the inverse of an exponential - this is logarithmic growth. On average, this would be O(log(n)) because we are iterating through each level. On each level we only check one node - performing a constant number of operations. | ||
// Space Complexity: O(1). We do not create a copy of the BST, we point to a node, and add a node. | ||
|
||
// based on the tests the keys are numeric and the values are names - therefore we should sort/look-up by key | ||
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.
👍
// Time Complexity: Worst case, O(n) (the BST would be a structure similar to a linked list. The BST grows exponentionally with respect to each level, so the total number of levels with respect to the total number of nodes is the inverse of an exponential - this is logarithmic growth. On average, this would be O(log(n)) because we are iterating through each level. On each level we only check one node - performing a constant number of operations. | ||
// Space Complexity: O(1). We do not create a copy of the BST, we point to a node, and return the value of the node whose input key matches the node's key, otherwise we return null. | ||
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.
👍 , correct time/space complexity given the unbalanced tree.
// Time Complexity: O(n), one constant time operation for every node | ||
// Space Complexity: O(n), the array will be of length n, and a recursive function will be called for every node, (n number of stacks) | ||
// inorder: left, root, right | ||
|
||
|
||
inorder() { |
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), one constant time operation for every node | ||
// Space Complexity: O(n), the array will be of length n, and a recursive function will be called for every node, (n number of stacks) | ||
// preorder: root, left, right | ||
preorder() { |
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), one constant time operation for every node | ||
// Space Complexity: O(n), the array will be of length n, and a recursive function will be called for every node, (n number of stacks) | ||
// postorder: left, right, root | ||
postorder() { |
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), every node has to be checked | ||
// Space Complexity: O(n) - worst case, if the BST is one long chain (skewed tree) then there will be n number of calls down the stack. On average, if the BST is more balanced, this can be O(log(n)) because the number of calls down the call stack will be logarithmic with respect to the number of nodes. The number of recursive calls will be at most the height of the tree. | ||
height(node=this.root) { |
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), the while loop will run n number of times (depends on the number of nodes). | ||
// Space Complexity: O(n), the result array will be of length n (it will contain information about all the nodes). The temporary (temp) array will never be longer than length n. | ||
bfs() { |
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.
👍 The time complexity is O(n^2) because temp.shift()
is an O(n) operation.
No description provided.