Skip to content

Time - Olga#15

Open
olgapatrakova wants to merge 1 commit intoAda-C13:masterfrom
olgapatrakova:master
Open

Time - Olga#15
olgapatrakova wants to merge 1 commit intoAda-C13:masterfrom
olgapatrakova:master

Conversation

@olgapatrakova
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 type, defines a way it should function, not inner implementation
Describe a Stack An abstract data type that serves as a collection of elements, with two main principal operations: push, which adds an element to the collection, and pop, which removes the most recently added element that was not yet removed.
What are the 5 methods in Stack and what does each do? push - adds a new element on top; pop - removes most recent/first element; empty? - checks if the stack has no elements; initialize - initializes a new object of a class Stack; to_s - returns stack elements as a string
Describe a Queue A queue is an abstract data type of entities that are maintained in a sequence and can be modified by the addition of entities at one end of the sequence and the removal of entities from the other end of the sequence
What are the 5 methods in Queue and what does each do? enqueue - add to the rear; dequeue - remove the element which was added first; front - shows the first element without dequeueing it; size - return how many elements there are in the Queue; empty? - checks if the queue is empty
What is the difference between implementing something and using something? Implementing is when you describe an algorithm of how a data structure works. Using is when you call methods of a data structure without knowing the algorithm of its implementation.

OPTIONAL JobSimulation

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

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 Olga, you hit all the learning goals here. Well done.

Comment on lines +3 to 5
# Time Complexity: O(n) - goes through all input elements
# Space Complexity: O(n) - stack will take at least half of symbols in string
def balanced(string)

Choose a reason for hiding this comment

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

👍

raise NotImplementedError, "Not implemented yet"
return true if string.length == 0

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

Choose a reason for hiding this comment

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

I love the use of a hash here!

Comment on lines +23 to 25
# Time Complexity: O(n) - goes through all input elements
# Space Complexity: O(1) - stack will never have more than 2 elements
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.

👍

@@ -1,31 +1,54 @@
class Queue

Choose a reason for hiding this comment

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

👍 , Well done, good work implementing a circular buffer!

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