0% found this document useful (0 votes)
4 views5 pages

DSOS Midsem Model Paper 1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views5 pages

DSOS Midsem Model Paper 1

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

MCQs on Recursion

1. Which of the following must a recursive function always have?


a) A loop
b) A base case
c) A global variable
d) A return statement

2. Which problem is best solved using recursion?


a) Sorting an array
b) Finding the largest number in an array
c) Computing factorial
d) Both (c) and (a)

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;

printf("%d ", n);

func(n - 1);

a) 3 2 1 0
b) 3 2 1
c) 1 2 3
d) 0 1 2 3

5. Which of the following problems is NOT typically solved using recursion?


a) Tower of Hanoi
b) Fibonacci Series
c) Matrix Multiplication
d) Factorial Calculation

MCQs on Static Variables

6. Which of the following is true about static variables in C?


a) They are stored in stack memory
b) They retain their value between function calls
c) They can only be accessed within the main() function
d) They are initialized to a random value
7. What will be the output of the following code?

void test() {

static int num = 5;

printf("%d ", num);

num++;

int main() {

test();

test();

return 0;

a) 5 5
b) 5 6
c) 6 7
d) 5 10

8. Where are static variables stored?


a) Stack
b) Heap
c) Data segment
d) Register

9. What is the initial value of an uninitialized static variable in C?


a) 0
b) Garbage value
c) 1
d) Depends on the system

MCQs on Stack

10. Which operation is used to insert an element into a stack?


a) Enqueue
b) Dequeue
c) Push
d) Pop

11. Which of the following is NOT an application of stacks?


a) Function calls
b) Undo operations
c) CPU scheduling
d) Expression evaluation
12. What happens when a stack overflows?
a) The program continues running normally
b) New elements are added at the bottom
c) It causes a runtime error
d) The last element is automatically removed

13. Which of the following correctly represents the stack operations?


a) Last In, First Out
b) First In, Last Out
c) First In, First Out
d) Last In, Last Out

MCQs on Queue

14. Which data structure follows FIFO (First In, First Out)?
a) Stack
b) Queue
c) Array
d) Tree

15. Which operation removes an element from a queue?


a) Push
b) Pop
c) Dequeue
d) Enqueue

16. Which real-life scenario is best represented by a queue?


a) A stack of plates
b) A line of people at a ticket counter
c) A set of nested function calls
d) A bookshelf

MCQs on Linked Lists

17. Which of the following is NOT a type of linked list?


a) Singly linked list
b) Doubly linked list
c) Circular linked list
d) Indexed linked list

18. What is the main advantage of a linked list over an array?


a) Faster access time
b) Uses less memory
c) Dynamic memory allocation
d) Fixed size

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

MCQs on Tower of Hanoi

21. The Tower of Hanoi problem follows which strategy?


a) Divide and Conquer
b) Greedy Algorithm
c) Backtracking
d) Dynamic Programming

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

MCQs on Fahrenheit to Celsius Conversion

24. Which formula correctly converts Fahrenheit (F) to Celsius (C)?


a) C = (F - 32) * 5 / 9
b) C = (F + 32) * 5 / 9
c) C = (F - 32) * 9 / 5
d) C = (F + 32) * 9 / 5

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

MCQs on Function Call Trees

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

You might also like