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

Branches, C. Gutierrez #37

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

Conversation

CEsGutierrez
Copy link

Stacks and Queues

Thanks for doing some brain yoga. You are now submitting this assignment!

Comprehension Questions

Question Answer
What is an ADT? Abstract Data Class. It is a class defined by its behavior not attributes.
Describe a Stack It is an ADT which follows a LIFO pattern
What are the 5 methods in Stack and what does each do? Initialize: it creates an instance of a Stack. Push: it adds a value to the end of the stack. Pop, it removes the last value added to the stack. Empty?: it evaluates to see if the stack is empty. View: it iterates through the stack to show its contents
Describe a Queue It is an ADT which follows a FIFO pattern
What are the 5 methods in Queue and what does each do? Initialize: it creates an instance of a Queue. Enqueue: it adds a value to the front of the stack. Dequeue: it removes a value from the back of the stack. This would have been the first item added to the Queue. Front: it returns the value at the front the queue. Empty?: it evaluates whether the stack is empty.
What is the difference between implementing something and using something? An implementation is the guts of how something works. For example, one can make a stack using a linked list or an array, both provide different properties, however, at the end of the day, because they are the backbone of a stack, they still must perform the desired methods and exhibit the desired behaviors. I think using it is the surface of the thing, that the stack, regardless of how it works under the hood, is able to perform the desired methods and exhibit the desired behaviors.

OPTIONAL JobSimulation

Question Answer
Did you include a sample run of your code as a comment?

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.

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.

Comment on lines +3 to 5
# Time Complexity: O(n)
# Space Complexity: O(1)
def balanced(string)

Choose a reason for hiding this comment

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

Since you're building expected_mirror up, this does have some space complexity. It should be O(n) space complexity.

Comment on lines +79 to 81
# Time Complexity: O(n)
# Space Complexity: O(1)
def evaluate_postfix(postfix_expression)

Choose a reason for hiding this comment

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

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)

Choose a reason for hiding this comment

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

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.

Comment on lines 27 to +41
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

Choose a reason for hiding this comment

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

This method isn't really using a circular buffer, but instead using an array with the front fixed at index 0.

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