Skip to content

Diana - Space#27

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

Diana - Space#27
dnguye2 wants to merge 5 commits intoAda-C13:masterfrom
dnguye2:master

Conversation

@dnguye2
Copy link

@dnguye2 dnguye2 commented Sep 9, 2020

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 when the public interface is hidden behind public methods. E.g. Stack using LinkedList
Describe a Stack Implemented through a linked list in which items are added or "pushed" to the top of the stack and removed or "popped" at the end of the stack. Summarized by: Last In First Out
What are the 5 methods in Stack and what does each do? -push: add element
-pop: remove element
-is_empty: check if stack is empty
-initialize: create LinkedList base for stack
-to_s: allow for easy to read output of stack
Describe a Queue Can be implemented with a circular buffer through an array or doubly linked list. Items are added by enqueuing and removed by dequeuing. Addition is through the back and removal is from the front. Best summarized by: Last In First Out
What are the 5 methods in Queue and what does each do? -enqueue: adds element to rear of queue
-dequeue: removes element from front of rear
-is_empty?: checks if queue is empty
-initialize: sets up initial queue
-size: gives size of queue
What is the difference between implementing something and using something? Implementation: building from scratch and knowing the logic–essentially theory of the something
Use: able to utilize without knowing the logic–application of the something

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.

Diana, nice work. You hit the main learning goals. Well done.

Comment on lines +3 to 6
# Time Complexity: O(n), will always have to traverse through the string
# Space Complexity: O(n), because in the worst case all char in string
# are opening brackets, best case would be O(1) where we push and pop every item
def balanced(string)

Choose a reason for hiding this comment

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

👍 , However you can dry up the case statement by using a hash instead. The has would have the open braces as the keys and the closing braces as the values.

return false if brace_hash[current_char] != char

@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 front
raise NotImplementedError, "Not yet implemented"
@front

Choose a reason for hiding this comment

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

Suggested change
@front
@store[@front]

Comment on lines 37 to 39
def size
raise NotImplementedError, "Not yet implemented"
@size
end

Choose a reason for hiding this comment

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

Size should be the number of elements in the queue. You can calculate it using the position of front and rear.

@@ -1,19 +1,20 @@
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