Stack and Queues Flashcards

1
Q

A list ADT with the restriction that insert and delete operations can only be performed at one end called the top-of-stack (TOS)

A

Stack

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

Stack is a list ADT with the restriction that insert and delete operations can only be performed at one end called the _____________

A

top-of-stack (TOS)

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

Stack follows the __________________ policy

A

Last In, First Out (LIFO)

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

2 Main Stack Operations

A

push(x) and pop()

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

Both push and pop operations operate on ________. It is updated after every push or pop

A

TOS

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

Other stack operations

A

peek() - return value of TOS
isFull() - checks if stack is full
isEmpty() - checks if stack is empty

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

Happens when you attempt to pop an empty stack

A

Stack Underflow Error

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

Happens when you attempt to push to a full stack

A

Stack Overflow Error

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

Initial value of TOS (Static Array Solution)

A

int top = -1;

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

Push Operation Pseudocode (Static Array)

A

push(e):

if top < LIMIT -1
top = top + 1
stack[top] = e
else
error “Stack Overflow”

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

Pop Operation Pseudocode (Static Array)

A

pop():

if top >= 0
top = top-1
return stack[top+1]
else
error “Stack Underflow”

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

Linked List Solution Stack

A

Normal Linked list, with insertion and deletion at head (TOS)

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

Applications of Stack

A

a) Balancing open/close symbols in PLs
b) Function calls (Recursion Stack)
c) Postfix expression evaluation

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

A list ADT with the restriction that insert is done at one end of the list and delete is done at the other

A

Queue

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

Queue follows the ____________________ policy.

A

First In, First Out (FIFO)

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

Main Queue Operations

A

Enqueue - add element at tail (rear)
Dequeue - delete at head (front)

17
Q

Happens when attempting to dequeue an empty queue

A

Queue Underflow

18
Q

Happens when attempting to enqueue to a full queue

A

Queue Overflow

19
Q

Initial value for head and tail variables in
Circular Array Solution (Queue)

A

int head = 0;
int tail = 0;

20
Q

Circular Increment and Decrement

A

Increment : tail = (tail+1)%LIMIT

21
Q

Pseudocode for Enqueue (Circular Array Solution)

A

enqueue(e):
tail = (tail+1)%LIMIT //Circular Increment

 if tail != head:
       queue[tail] = e;
 else
     error "Queue Overflow"
22
Q

Pseudocode for Dequeue (Circular Array Solution)

A

dequeue():
if head!=tail
head = (head+1)%LIMIT
return queue[head]
else
error “Queue Underflow”

23
Q

Queue Linked List Solution

A

Track and Update pointers for head and tail node, and perform insertion on one end and deletion on the other.

24
Q

Queue Applications

A

CPU Scheduling
Routing
Event Handling

25
Q
A