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

Aimee 👾 - Fire 🔥 #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Aimee 👾 - Fire 🔥 #2

wants to merge 4 commits into from

Conversation

marks214
Copy link

No description provided.

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, you hit the learning goals here Aimee. Well done. I did have one comment on your time complexity for bfs.

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

Choose a reason for hiding this comment

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

👍

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

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.

Comment on lines +81 to 86
// 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() {

Choose a reason for hiding this comment

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

👍

Comment on lines +118 to 121
// 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() {

Choose a reason for hiding this comment

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

👍

Comment on lines +152 to 155
// 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() {

Choose a reason for hiding this comment

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

👍

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

Choose a reason for hiding this comment

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

👍

Comment on lines +203 to 205
// 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() {

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.

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