Branches, C. Gutierrez#37
Conversation
CheezItMan
left a comment
There was a problem hiding this comment.
Your Queue class does not use a circular buffer. Instead it's using an array with an O(n) dequeue operation. It works, but it's not the assignment. Your Stack class does work and work well.
| # Time Complexity: O(n) | ||
| # Space Complexity: O(1) | ||
| def balanced(string) |
There was a problem hiding this comment.
Since you're building expected_mirror up, this does have some space complexity. It should be O(n) space complexity.
| # Time Complexity: O(n) | ||
| # Space Complexity: O(1) | ||
| def evaluate_postfix(postfix_expression) |
There was a problem hiding this comment.
This doesn't seem to handle postfix expressions with more than 3 terms.
| @back = 0 | ||
| # this adds a viable index number, because for this part of the "if" statement, the array is empty, both front and back are 0 | ||
| else | ||
| @store.push(value) |
There was a problem hiding this comment.
Using push will always put an element to the end of the array, there's no way to "wrap" the back around the internal array.
| def dequeue | ||
| raise NotImplementedError, "Not yet implemented" | ||
|
|
||
| temp = @store[0] | ||
|
|
||
| if @back == 0 | ||
| @store.slice!(0) | ||
| @front = -1 | ||
| @back = -1 | ||
| return temp | ||
| end | ||
|
|
||
| @back -= 1 | ||
| @store.slice!(0) | ||
|
|
||
| return temp |
There was a problem hiding this comment.
This method isn't really using a circular buffer, but instead using an array with the front fixed at index 0.
Stacks and Queues
Thanks for doing some brain yoga. You are now submitting this assignment!
Comprehension Questions
OPTIONAL JobSimulation