Skip to content

Time - Sharon #17

Open
sharonkeikei wants to merge 5 commits intoAda-C13:masterfrom
sharonkeikei:master
Open

Time - Sharon #17
sharonkeikei wants to merge 5 commits intoAda-C13:masterfrom
sharonkeikei:master

Conversation

@sharonkeikei
Copy link
Copy Markdown

Stacks and Queues

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

Comprehension Questions

Question Answer
What is an ADT? An Abstract Data Type 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? 1. push - Add an element to the top of the stack 2.pop - Remove & return the element from the top 3. is_empty - returns true if the stack is empty 4. size - return the size of the stack 5. last - return the last element of the stack
Describe a Queue A Queue is an Abstract Data Structure which stores data and allows access in a First-In-First-Out order (FIFO)
What are the 5 methods in Queue and what does each do? 1.enqueue - add an element to the rear of the queue 2. dequeue - Remove & return the element from the front 3. is_empty - returns true if the queue is empty 4. size - return the size of the stack 5. front - returning the first element of the queue
What is the difference between implementing something and using something? Implementation puts importance on how it works and using something puts importance on whether it works or not.

OPTIONAL JobSimulation

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

Copy link
Copy Markdown

@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.

Well done Sharon, you hit all the learning goals here. Take a look at my comments and let me know what questions you have.

Comment thread lib/problems.rb
Comment on lines +3 to 5
# Time Complexity: O(n)
# Space Complexity: O(n)
def balanced(string)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍 Instead of using the case statements, you could instead use a hash where the keys are the close braces and the values are the matching open braces.

Comment thread lib/queue.rb
@size = 20
end

def enqueue(element)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍
You can make @rear go to the next index with @rear = (@rear + 1) % size

Comment thread lib/queue.rb
end
end

def dequeue
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You can adjust @front the same way rear can change (See above).

Comment thread lib/queue.rb
return @store[@front]
end

def size
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍

Comment thread lib/stack.rb
@@ -1,19 +1,22 @@
class Stack
Copy link
Copy Markdown

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