Question 1
EasyWhich data structure does a program use to manage function calls, including recursion?
- A.
Popular companies
Prepare company by company
Hiring pattern, syllabus, past questions and mocks for each company.
All companiesPractice by subject
Data Structures and Algorithms
Which data structure does a program use to manage function calls, including recursion?
Queue
Stack
Heap
Hash table
Answer: B
Each call pushes a frame (parameters, local variables, return address) onto the call stack, and returning pops it. Last call in, first out.
Which principle does a stack follow?
Random access
LIFO (last in, first out)
Priority order
FIFO (first in, first out)
Answer: B
The last item pushed is the first popped, like a stack of plates.
Which operation adds an element to the top of a stack?
push
enqueue
pop
peek
Answer: A
pop removes the top element; peek reads it without removing it.
What is the output of this code?
s = []
s.append(1)
s.append(2)
s.append(3)
print(s.pop())
2
3
[1, 2]
1
Answer: B
pop() removes and returns the last element pushed, 3.
Which of these uses a stack?
A printer queue
The undo feature of a text editor
Breadth-first search
A ticket counter line
Answer: B
The most recent action is undone first — LIFO.
What is stack overflow?
A stack with one element
Popping from an empty stack
Pushing onto a stack that is already full (or recursing too deeply)
Sorting a stack
Answer: C
Popping from an empty stack is stack underflow.
What is the time complexity of push and pop on a stack implemented with an array (with spare capacity)?
O(log n)
O(1)
O(n²)
O(n)
Answer: B
Both work only at the top.
Which traversal of a graph naturally uses a stack?
Level-order traversal
Breadth-first search
Depth-first search
Dijkstra's algorithm
Answer: C
DFS goes as deep as possible, backtracking in LIFO order — explicitly with a stack or implicitly with recursion.
Which operation removes the top element of a stack?
enqueue
pop
peek
push
Answer: B
pop removes and returns the most recently pushed element.
Which operation returns the top element of a stack without removing it?
peek (or top)
push
pop
dequeue
Answer: A
peek lets you look before deciding whether to pop.