-
Notifications
You must be signed in to change notification settings - Fork 49
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 - Erika #33
base: master
Are you sure you want to change the base?
Branches - Erika #33
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some issues with Queue and your balanced
method here. Take a look at my comments and let me know what questions you have.
lib/problems.rb
Outdated
openers = ["{", "[", "("] | ||
closers = ["}", "]", ")"] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest using a hash here instead of arrays where the key is an open brace and the value is the close.
lib/problems.rb
Outdated
until count == length || stack_size > string.length/2 | ||
char = string[count] | ||
# if the value is in openers, add to stack | ||
if openers.include?(char) | ||
stack.push(char) | ||
stack_size += 1 | ||
# if the value is in closers, pop from stack | ||
else | ||
if closers.include?(char) | ||
stack.pop | ||
stack_size -= 1 | ||
# if it's in neither, return false | ||
else | ||
return false | ||
end | ||
end | ||
count += 1 | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're on the right track here. I suggest, like I did above using a hash to match up open and close braces.
lib/queue.rb
Outdated
def enqueue(element) | ||
raise NotImplementedError, "Not yet implemented" | ||
end | ||
def enqueue(element) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about when the queue is empty, and what about when it's full?
lib/queue.rb
Outdated
end | ||
|
||
def size | ||
raise NotImplementedError, "Not yet implemented" | ||
end | ||
|
||
def empty? | ||
raise NotImplementedError, "Not yet implemented" | ||
return true if @front == -1 && @rear == -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're assuming the queue is empty if front and rear are -1, but your initialize method sets them to 0.
Also when you dequeue above if the queue is now empty, you would then need to set them to -1.
…_first as push/pop for best time/space
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work Erika. You hit the main learning goals here, well done.
# Time Complexity: ? | ||
# Space Complexity: ? | ||
def balanced(string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 , Time & space complexity?
end | ||
|
||
def dequeue | ||
raise NotImplementedError, "Not yet implemented" | ||
def dequeue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
end | ||
|
||
def front | ||
raise NotImplementedError, "Not yet implemented" | ||
return @store[@front] | ||
end | ||
|
||
def size |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
def empty? | ||
raise NotImplementedError, "Not yet implemented" | ||
return @front == @rear | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should actually be:
return @front == -1 && @rear == -1
Stacks and Queues
Thanks for doing some brain yoga. You are now submitting this assignment!
Comprehension Questions
OPTIONAL JobSimulation