DSA · Question paper

CET-1 · 1 Sep 2026

Data Structures & Algorithms (C2310C5) · CET-I · 1 September 2026 · 30 marks · 10:10 – 11:40 am ITM (SLS) Baroda University · B.Tech CSE/CSN/IT/AI · Semester III, Odd Semester 2026. Questions transcribed from the original paper. Solutions are written by CampusLoop; check them against your class notes.

Q1. Multiple choice questions [6]

1. Data structures are used to: a) Organize and store data efficiently · b) Control program flow · c) Perform compilation · d) None of the above Answer: (a).

2. Which of the following operations has the best possible time complexity? a) O(log n) · b) O(n) · c) O(1) · d) O(n²) Answer: (c) O(1).

3. Which operation inserts an element into a stack? A) Pop · B) Push · C) Peek · D) Delete Answer: (B) Push.

4. What is the condition when a stack contains no elements? A) Overflow · B) Underflow · C) Collision · D) Saturation Answer: (B) Underflow (popping from an empty stack; TOP = −1).

5. Which of the following is an example of a non-linear data structure? a) Array · b) Stack · c) Queue · d) Graph Answer: (d) Graph.

6. Every recursive function must have a: A) Loop · B) Pointer · C) Base condition · D) Structure Answer: (C) Base condition.

Q2. Answer any THREE out of FIVE [9]

Q2.1 What is pseudocode? Write one example.

Pseudocode is an informal, language-independent description of an algorithm using structured English and programming-like constructs (IF, REPEAT, WHILE, ←), without strict syntax. It is easy to read, easy to convert into any language, and lets you focus on logic.

Example: sum of the first N natural numbers

Procedure SUM_N(N)
1. [Initialise]   SUM ← 0
2. [Loop]         Repeat for I = 1 to N
                      SUM ← SUM + I
3. [Output]       Write SUM
4. [Finished]     Return

Q2.2 Explain Big O, Big Omega and Big Theta with examples and graphs.

O: f(n) ≤ c·g(n) (upper bound, worst case); Ω: f(n) ≥ c·g(n) (lower bound, best case); Θ: c₁g(n) ≤ f(n) ≤ c₂g(n) (tight bound), all for n ≥ n₀. Example 3n + 2 = Θ(n). Full answer with graph descriptions: DSA CET-1 2025, Q2.2.

Q2.3 Explain step by step the Tower of Hanoi problem for 3 disks with a diagram.

Pegs A (source), B (auxiliary), C (destination); disks 1 (smallest) to 3 (largest) on A. Minimum moves = 2³ − 1 = 7:

MoveDiskFrom → ToABC
start3 2 1
11A → C3 21
22A → B321
31C → B32 1
43A → C2 13
51B → A123
62B → C13 2
71A → C3 2 1

Moves 1–3 move the top two disks to B, move 4 moves the largest disk, moves 5–7 move the two disks onto it (the recursion TOH(n−1, A, C, B); move n; TOH(n−1, B, A, C)). Draw three pegs for each state. Algorithm: DSA CET-2 2025, Q2.1.

Q2.4 Differentiate between primitive and non-primitive data types.

Primitive: built-in, single value (int, float, char, double). Non-primitive: built from primitives, hold collections (array, structure, linked list, stack, queue, tree, graph), divided into linear and non-linear. Full table: DSA end-sem 2025, Q2.5.

Q2.5 Write a recursive program to calculate the factorial of a number.

#include <stdio.h>

long long factorial(int n) {
    if (n <= 1) return 1;            /* base case */
    return n * factorial(n - 1);     /* recursive case */
}

int main(void) {
    int n;
    printf("Enter a number: ");
    scanf("%d", &n);
    if (n < 0) printf("Factorial is not defined for negative numbers\n");
    else printf("%d! = %lld\n", n, factorial(n));   /* e.g. 5! = 120 */
    return 0;
}

Trace for n = 4: factorial(4) → 4 × factorial(3) → 4 × 3 × factorial(2) → 4 × 3 × 2 × factorial(1) = 24.