-
Notifications
You must be signed in to change notification settings - Fork 6
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
Ringo - Earth #3
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.
Well done Ringo, you hit the learning goals. I had one comment on dequeue, but otherwise this works well.
Time Complexity: O(n), the function has to visit every node once | ||
but operations performed in that loop are O(1) | ||
Space Complexity: O(n), worst case scenario the stack could have on it | ||
every character in the string | ||
*/ | ||
const balanced = (str) => { |
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 function has to check every character in expr, | ||
but operations in the for loop are O(1) | ||
Space Complexity: O(n), the controlling factor is the height of the stack, | ||
which does not grow quickly with longer expr in a normal use case but I suppose | ||
in a worst case scenario with some weird postfix expressions would increase in size | ||
linear to the length of the weird expression you were using | ||
*/ | ||
const evaluatePostfix = (expr) => { |
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.
👍
} else { | ||
this.store[this.tail] = element; | ||
this.tail = (this.tail + 1) % QUEUE_SIZE; | ||
} | ||
} | ||
|
||
dequeue() { |
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.
👍 Very compact! However what happens if you dequeue an empty queue?
throw new Error("This method has not been implemented!"); | ||
this.store = new Array(QUEUE_SIZE); | ||
this.head = 0; | ||
this.tail = 0; | ||
} | ||
|
||
enqueue(element) { |
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, very compact
No description provided.