DSOS Midsem Model Paper 1
DSOS Midsem Model Paper 1
3. Which of the following recursive functions correctly calculates the sum of the first n
natural numbers?
a) return sum(n-1) + n;
b) return sum(n-1) - n;
c) return sum(n) + sum(n-1);
d) return sum(n+1) + n;
4. What will be the output of the following recursive function for func(3)?
void func(int n) {
if (n == 0) return;
func(n - 1);
a) 3 2 1 0
b) 3 2 1
c) 1 2 3
d) 0 1 2 3
void test() {
num++;
int main() {
test();
test();
return 0;
a) 5 5
b) 5 6
c) 6 7
d) 5 10
MCQs on Stack
MCQs on Queue
14. Which data structure follows FIFO (First In, First Out)?
a) Stack
b) Queue
c) Array
d) Tree
19. Which function is used to insert a node at the beginning of a linked list?
a) insertBeginning(struct Node* head, int data);
b) insert(struct Node** head, int data);
c) insert(struct Node* head, int data);
d) insertFirst(struct Node* head, int data);
20. What will happen if a linked list node is deleted but not freed in C?
a) The program crashes immediately
b) It leads to memory leakage
c) The node gets automatically freed
d) The linked list gets corrupted
22. In Tower of Hanoi, how many moves are required for n = 3 disks?
a) 3
b) 5
c) 7
d) 9
23. What is the minimum number of moves required to solve Tower of Hanoi for 5 disks?
a) 15
b) 25
c) 31
d) 63
25. Which of the following is NOT a correct way to store temperature values in a linked list?
a) Using an array inside a linked list node
b) Using a separate linked list for each temperature unit
c) Storing Fahrenheit and Celsius together in each node
d) Storing only Fahrenheit and converting it when needed
26. How many function calls are made in fact(4) when using a recursive factorial function?
a) 3
b) 4
c) 5
d) 6
27. What is the structure formed when representing recursive function calls visually?
a) Linked List
b) Stack
c) Tree
d) Queue