Skip to content

Conversation

@HabenFoto
Copy link

@HabenFoto HabenFoto commented Sep 8, 2020

Stacks and Queues

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

Comprehension Questions

Question Answer
What is an ADT? ADT is a data type which specifies an external interface without prescribing a specific implementation.
Describe a Stack A Stack is an Abstract Data Type which stores data and allows access in a Last-In-First-Out order (LIFO).
What are the 5 methods in Stack and what does each do? The push() method pushes an element, that is passed as the parameter, on the top of the stack. The pop() method removes and returns the top element of the stack. The peek() method returns the element on the top of the stack but does not remove it. The isEmpty() method returns true if the stack is empty, otherwise, it returns false. The search() method determines whether an object, which is the input parameter of the function, exists in the stack or not.
Describe a Queue A Queue is an Abstract Data Structure which stores data and allows access in a First-In-First-Out order (FIFO). Elements are added to the rear and removed from the front.
What are the 5 methods in Queue and what does each do? The enqueue() method adds the specified element into the rear of the queue. The size() method returns the number of elements in the queue. The isEmpty() method returns true if the queue is empty, otherwise, it returns false. The dequeue() method returns and removes the head of the queue. The peek() method returns the head of the queue without removing it. It returns null if the queue is empty.
What is the difference between implementing something and using something? Implementing is when we write/design a logic while using is taking advantage of the existing implementation without knowing what goes under the hood.

OPTIONAL JobSimulation

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

lib/problems.rb Outdated
if char == '{' || char == '(' || char == '['
opening_brackets.push(char)
else
# compare if the last opening bracket matches with the current closing bracket in char

Choose a reason for hiding this comment

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

Could you use a hash to see if the opening and closing braces match?

matching_braces = {
  "{" => "}",
  "(" => ")",
  "[" => "]",
}

Copy link
Author

Choose a reason for hiding this comment

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

Thanks, Chris. Refactored it based on your suggestion.

Comment on lines +29 to 31
# Time Complexity: O(n)
# Space Complexity: O(n)
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.

👍

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 Haben, this hits all the learning goals well done.

@back = 0
end

def enqueue(element)

Choose a reason for hiding this comment

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

👍

def size
raise NotImplementedError, "Not yet implemented"
end
def dequeue

Choose a reason for hiding this comment

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

👍

element
end

def to_s

Choose a reason for hiding this comment

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

👍

@@ -1,19 +1,22 @@
class Stack

Choose a reason for hiding this comment

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

👍

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