Stacks Flashcards

(35 cards)

1
Q

Which structure allows you to reverse a string by pushing each character and then popping them sequentially?

A. Recursion
B. Array
C. Queue
D. Stack

A

D. Stack

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

What happens when you push to a full stack?

A. Returns -999
B. Throws exception
C. Stack expands
D. Clears stack

A

B. Throws exception

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

Which of the following is not a valid stack operation?

A. Peek
B. Push
C. Sort
D. Pop

A

C. Sort

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

Which of the following is a postfix expression?

A. + A B
B. A B +
C. A * (B + C)
D. A + B

A

B. A B +

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

Which method checks if the stack is empty?

A. peek
B. isFull
C. clear
D. isEmpty

A

D. isEmpty

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

What is the result of popping all elements from a stack?

A. Empty stack
B. Overflow
C. Segmentation fault
D. Full stack

A

A. Empty stack

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

Which operation removes the top item from the stack?

A. delete
B. peek
C. remove
D. pop

A

D. pop

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

Which data structure is used to reverse a string using stack logic?

A. Tree
B. Graph
C. Queue
D. Stack

A

D. Stack

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

What does the term LIFO stand for in stack operations?

A. Least Important First Out
B. Last Item First Out
C. Last In First Out
D. Last In Fast Out

A

C. Last In First Out

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

What is the time complexity of push and pop operations in a stack?

A. O(n)
B. O(log n)
C. O(1)
D. O(n²)

A

C. O(1)

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

What is the default top value when a new stack is created?

A. 0
B. null
C. -1
D. 1

A

C. -1

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

Which application uses stacks?

A. Hashing
B. Breadth-first search
C. Priority queue
D. Undo feature

A

D. Undo feature

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

Which of the following is true about postfix notation?

A. Operators come before operands
B. Operators come after operands
C. It’s ambiguous
D. Parentheses are required

A

B. Operators come after operands

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

Which of the following is true about stack ADT?

A. It allows random access
B. It has fixed size
C. It follows FIFO
D. It allows access only to the top

A

D. It allows access only to the top

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

What is the result of peek() on an empty stack?

A. null
B. -999
C. 0
D. top

A

A. null

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

Which Java class is used for predefined stack operations?

A. java.util.Array
B. java.util.List
C. java.util.Stack
D. java.util.Queue

A

C. java.util.Stack

17
Q

What does the peek operation do in a stack?

A. Removes top
B. Views top
C. Clears stack
D. Adds top

18
Q

Which data structure is typically used to implement a stack?

A. Queue
B. Array
C. Tree
D. Graph

19
Q

Which of the following is NOT a valid stack operation?

A. peek
B. push
C. delete
D. pop

20
Q

Which operation adds an item to the top of the stack?

A. pop
B. peek
C. insert
D. push

21
Q

Which of the following is true about stack in system memory?

A. It stores static data
B. It stores heap
C. It stores global variables
D. It stores function calls

A

D. It stores function calls

22
Q

In which of the following scenarios would the use of multiple stacks be a valid and common approach?

A. Binary Search
B. Expression Conversion and Evaluation
C. Hashing
D. Bubble Sort

A

B. Expression Conversion and Evaluation

23
Q

What is the output of pushing 1, 2, 3 and popping once?

A. 3
B. 1
C. 0
D. 2

24
Q

Which of the following is true about linked list-based stack?

A. Dynamic size
B. Fixed size
C. Slower than array
D. Requires sorting

A

A. Dynamic size

25
Which condition causes stack overflow? A. Pushing into full stack B. Peeking top C. Reversing stack D. Popping from empty stack
A. Pushing into full stack
26
What is the result of evaluating the prefix expression + 5 * 3 2? A. 10 B. 13 C. 16 D. 11
D. 11
27
Which of the following is the correct order of operations in postfix evaluation? A. Right to left B. Left to right C. Top to bottom D. Bottom to top
B. Left to right
28
Which of the following best describes stack ADT? A. Linear, restricted access B. Non-linear, random access C. Linear, dynamic access D. Circular, indexed access
A. Linear, restricted access
29
What is the role of stack in recursion? A. Stores function calls B. Stores variables C. Stores loops D. Stores return values
A. Stores function calls
30
What is the result of evaluating the postfix expression 5 3 + 2 *? A. 10 B. 11 C. 16 D. 13
C. 16
31
Which expression evaluation uses stacks? A. Prefix B. Infix C. Postfix D. All of the above
D. All of the above
32
What is the result of evaluating the postfix expression 6 2 / 3 -? A. 3 B. 2 C. 0 D. 1
C. 0
33
Which of the following is not a valid postfix expression? A. AB+ B. A+BC+ C. ABC+* D. AB+C*
B. A+BC+
34
What is the main drawback of array-based stack implementation? A. Complex syntax B. Fixed size C. Slow access D. Memory overflow
B. Fixed size
35
Which of the following is true about stack ADT in Java? A. Stack is an interface B. Stack is abstract C. Stack is a class D. Stack is deprecated
C. Stack is a class