WorksheetsQUIZ-3
Total questions: 20
Worksheet time: 20mins
What is recursion?
A. A function calling itself
B. A loop inside another loop
C. A function that returns another function
D. A function that never terminates
What happens if a recursive function has no base condition?
A. Program runs faster
B. Program stops automatically
C. Infinite recursion → stack overflow
D. Output becomes zero
Which of the following best explains why the Fibonacci program becomes slow for large input values?
A. Because recursion is not allowed in C
B. Because each function call stores its value in a global array
C. Because multiple recursive calls recompute the same subproblems
D. Because printf() delays execution
For a Tower of Hanoi problem with n disks, what is the total number of moves made by the program?
A. n²
B. 2ⁿ
C. 2ⁿ − 1
D. n!
What is a queue in data structures?
A. A structure where the last inserted element is removed first
B. A linear data structure that follows FIFO (First In First Out)
C. A structure used only for tree traversal
D. A structure where insertion and deletion happen at the same end
Which of the following operations may lead to unused empty space in the queue?
A. insert() only
B. rem() only
C. A combination of insert() and rem()
D. display()
If f = 2 and r = 4, what is the maximum number of elements remaining in the queue?
A. 2
B. 3
C. 4
D. 5
After performing the operations Insert(5), Insert(10), Insert(15), Remove(), Insert(20), what are the values of f and r?
A. f = 0, r = 2
B. f = 1, r = 3
C. f = 1, r = 2
D. f = 2, r = 3
What will be printed by display() if f=2, r=4 and q = {10,20,30,40,50}?
A 10 20
B. 30 40 50
C. 20 30 40 50
D. Nothing
Consider the following code snippet from the Queue program:
if(r == MAX-1) {
printf("Queue is full"); return; }
What condition is this checking?
A. Underflow condition
B. Overflow condition
C. Queue is empty
D. Queue has only one element
Look at this deletion code snippet:
if(f == r) f = r = -1;
else f = f + 1;
What does the line f = r = -1 represent?
A. Queue is full
B. Queue contains one element, and it was deleted
C. Queue needs to be sorted
D. New element inserted at front
What is the logical error here?
for(int i = r; i >= f; i--) printf("%d ", q[i]);
A. It prints queue in FIFO order
B. It prints queue in reverse order (wrong behavior)
C. It deletes elements
D. It causes overflow
In a circular queue, the queue is considered full when:
A. f == r
B. (r + 1) % MAX == f
C. f == -1
D. r == -1
The initial values of front (f) and rear (r) in the given program are:
A. f = 0, r = 0
B. f = 1, r = 1
C. f = -1, r = -1
D. f = MAX
The delete operation prints which message when the queue is empty?
A. "cq is full"
B. "deleted item"
C. "cq is empty"
D. "invalid choice"
What condition resets both f and r to -1 during deletion?
A. When queue is full
B. When f == r
C. When f == -1
D. When user enters invalid choice
In the display() function, the queue is printed until:
A. i == f
B. i == -1
C. i != r
D. i == MAX
The insert() function uses which formula to update rear (r)?
A. r++
B. r = (r - 1) % MAX
C. r = (r + 1) % MAX
D. r = MAX - 1
Why is the input format for reading a character in insert() written as scanf(" %c",&e); with a space before %c?
A. To skip leading whitespaces/newlines
B. To restrict input to alphabets only
C. To convert char to ASCII
D. To avoid overflow
while (i != r) {
printf("%c ", cq[i]);
i = (i + 1);
}
What is the bug?
A. Missing semicolon
B. i = (i + 1); must be i = (i + 1) % MAX
C. Condition must be i == r
D. Array index must start at 1
