Stack Flashcards

1
Q

what are the main operations on a stack?

A

Push
Top
Pop
Empty

all of them are O(1) with an array or even with a list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What kind of problem u can fix with a stack?

A

Balanced brackets

u have a string with () and [] and u want to know if they are balanced or not

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

how to solve the balanced bracket problem with a stack?

A

loop through the string:
if the char is equal to a left bracket push it to the stack
if it doesn’t get the top one from the stack and compare it to see if it equals the right bracket if it doesn’t then they don’t match and as u can see the last entered bracket in the stack will be the first one out

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what are the two types to implement a stack?

A

using linked list or an array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what is a stack order of operations ?

A

LIFO

Last in First Out

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

is stack a concrete class or an ADT?

A

it’s the both of them as an ADT means that there is an implementation of an idea of a stack push , pop , top and it doesn’t mean that u have to inherit from it to be and ADT

How well did you know this?
1
Not at all
2
3
4
5
Perfectly