Top Banner Ad
2026-27 Model Paper · Predicted Practice SetSyllabus-aligned practice paper with marking scheme
ACS201 · 2026-27 Model Paper (Set 1)22 Questions

Essentials of Data Structures — 2026-27 Model Paper (Set 1)

Section A

2 Marks Each · 4 questions
Q62MUnit 4 — binary search
Survival Mode

What is the condition required for binary search?

Answer: Binary search requires the data to be sorted, either in ascending or descending order according to the comparison rule. It repeatedly compares the key with the middle element and discards half of the search range. (2 marks) Result: Binary search can be applied only to a sorted list or array.

Key Points

  • Data must be sorted (2 marks)
  • Comparison with middle element discards half of the search range
Q72MUnit 5 — Binary Search Tree
Survival Mode

Define a Binary Search Tree (BST).

Answer: A Binary Search Tree (BST) is a binary tree in which, for every node, keys in the left subtree are smaller and keys in the right subtree are greater, by the usual convention. This property makes search, insertion and deletion efficient. (2 marks) Result: A BST stores smaller keys to the left and greater keys to the right of each node.

Key Points

  • Binary tree with left subtree keys smaller and right subtree keys greater (2 marks)
  • Property supports efficient search, insertion and deletion
Q1(a)7MUnit 1 — Array
Survival ModePredicted

(a) Explain array operations: insertion, deletion, search, and traversal. Illustrate insertion and deletion with an example array.

Concept / Given Data: An array is a collection of finite homogeneous data elements stored in contiguous memory locations. Let us analyze the four fundamental operations: Traversal, Search, Insertion, and Deletion, illustrated with an initial array A=[10,20,30,40]A = [10, 20, 30, 40] of current size n=4n = 4.

Key Formula / Principle: Address(A[i])=Base Address+(i×Size of Element)\text{Address}(A[i]) = \text{Base Address} + (i \times \text{Size of Element})

Step-by-Step Solution / Working:

  1. Traversal: Visiting every element of the array exactly once to perform operations like printing or updating. Time complexity is O(n)O(n).
  2. Search: Finding the location of a target value. In an unsorted array, linear search scans from index 00 to n−1n-1, taking O(n)O(n) time.
  3. Insertion: Adding an element at a specific index kk. To insert 2525 at index 22 in A=[10,20,30,40]A = [10, 20, 30, 40]:
    • Shift elements from index 33 and 22 one position to the right: 4040 moves to index 44, 3030 moves to index 33.
    • Write 2525 into index 22.
    • Resulting array: A=[10,20,25,30,40]A = [10, 20, 25, 30, 40], size becomes 55. Time complexity in worst-case (inserting at front) is O(n)O(n).
  4. Deletion: Removing an element from a specific index. To delete 3030 from the updated array where it resides at index 33:
    • Shift subsequent elements one position to the left: element 4040 at index 44 moves into index 33.
    • Decrement active size n=n−1n = n - 1.
    • Resulting array: A=[10,20,25,40]A = [10, 20, 25, 40], size becomes 44. Time complexity is O(n)O(n) due to shifting.

Result: Array operations are efficient for indexing (O(1)O(1)) but costly for middle insertions and deletions (O(n)O(n)) due to mandatory element shifting.

Tip from Examiner: Always trace index shifts explicitly with arrows or step-by-step arrays to earn full credit for insertion and deletion questions.

Key Points

  • Traversal visits each array element sequentially in O(n) time.
  • Search finds target indices via linear or binary traversal methods.
  • Insertion shifts right-side elements to make room, taking O(n) time.
  • Deletion shifts left-side elements to fill the gap, taking O(n) time.
Q1(b)7MUnit 1 — Array
Core Concept

(b) What is a 2D array? Explain matrix addition and transpose with suitable examples and mention one real-world application.

Concept / Given Data

A 2D array (matrix) is a collection of data elements arranged in rows and columns, indexed by two subscripts a[i][j]a[i][j] where ii represents the row index and jj represents the column index. In memory, it is typically stored in contiguous locations in either row-major or column-major order. In AI and machine learning, 2D arrays are fundamental: grayscale images are represented as 2D matrices where each entry corresponds to a pixel intensity value.

Key Formula / Principle: Matrix Addition: C[i][j]=A[i][j]+B[i][j](0≤i<m,0≤j<n)\text{Matrix Addition: } C[i][j] = A[i][j] + B[i][j] \quad (0 \le i < m, 0 \le j < n) Matrix Transpose: T[j][i]=A[i][j]\text{Matrix Transpose: } T[j][i] = A[i][j]

Step-by-Step Solution & Working

  1. Matrix Addition Working: Given two matrices AA and BB of identical dimensions m×nm \times n, each element at position (i,j)(i, j) in matrix AA is added to the corresponding element at position (i,j)(i, j) in matrix BB. The resulting sum is stored in a new matrix CC of the same dimensions.
  2. Matrix Transpose Working: Given a matrix AA of dimensions m×nm \times n, its transpose TT is formed by swapping its rows and columns, resulting in dimensions n×mn \times m. The element at row ii, column jj of AA moves to row jj, column ii of TT.
  3. Numerical Example: Let matrix A=(1234)A = \begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix} and B=(5678)B = \begin{pmatrix} 5 & 6 \\ 7 & 8 \end{pmatrix}.
    • Addition Result CC: C[0][0]=1+5=6C[0][0] = 1+5=6, C[0][1]=2+6=8C[0][1] = 2+6=8, C[1][0]=3+7=10C[1][0] = 3+7=10, C[1][1]=4+8=12C[1][1] = 4+8=12. Thus, C=(681012)C = \begin{pmatrix} 6 & 8 \\ 10 & 12 \end{pmatrix}.
    • Transpose Result of AA: T[0][0]=A[0][0]=1T[0][0] = A[0][0]=1, T[0][1]=A[1][0]=3T[0][1] = A[1][0]=3, T[1][0]=A[0][1]=2T[1][0] = A[0][1]=2, T[1][1]=A[1][1]=4T[1][1] = A[1][1]=4. Thus, T=(1324)T = \begin{pmatrix} 1 & 3 \\ 2 & 4 \end{pmatrix}.
  4. Real-World Application: Grayscale image processing, where an image is treated as a 2D matrix of pixels and manipulated via matrix transformations.

Result: Matrix addition combines corresponding elements in O(m×n)O(m \times n) time, while transpose swaps indices yielding an n×mn \times m matrix.

Tip from Examiner: Always check if matrix dimensions match ($m_1=m_2$ and $n_1=n_2$) before attempting addition, otherwise an arithmetic dimension mismatch error occurs.

Key Points

  • A 2D array uses two indices ii and jj to represent rows and columns.
  • Matrix addition requires identical dimensions and adds element-wise: C[i][j]=A[i][j]+B[i][j]C[i][j] = A[i][j] + B[i][j].
  • Matrix transpose swaps row and column indices: T[j][i]=A[i][j]T[j][i] = A[i][j].
  • Real-world connection includes grayscale image representation as a 2D matrix.

Section B

7 Marks Each · 12 questions
Q12MUnit 1 — Data structure
Survival Mode

Define a data structure. Give one example.

A data structure is a specific way of organising, storing and accessing data so that operations can be performed efficiently. It defines the relationships among elements, the allowed operations and the memory layout. Example: an array stores elements in contiguous memory, enabling O(1)O(1) access.

Key Points

  • Organises data
  • Defines operations
  • Efficient access
  • Example: array
Q22MUnit 1 — Array
Core Concept

What is the time complexity of accessing an element in an array by index?

Accessing an array element by index has time complexity O(1)O(1), i.e., constant time. The memory address of a[i]a[i] is computed directly as base+i×element_size\text{base} + i \times \text{element\_size}, so the CPU jumps straight to the location without scanning other elements, regardless of the total array size nn.

Key Points

  • Array indexing is O(1) because address = base + i * element_size (direct computation, no loop).
  • This is why arrays are called 'random access' structures.
  • Contrast: insert/delete in the middle is O(n) due to shifting, but pure access is always O(1).
Q32MUnit 2 — why linked list over array
Survival Mode

State one advantage of a linked list over an array.

Answer: A linked list can grow or shrink dynamically at runtime and allows efficient insertion or deletion at a known position by changing pointers, without shifting all elements as an array must. (2 marks) Result: Dynamic size and pointer-based insertion or deletion without shifting are the main advantages of a linked list over an array.

Key Points

  • Can grow or shrink dynamically at runtime (2 marks)
  • Insertion or deletion at a known position changes pointers without shifting elements
Q42MUnit 3 — Stack
Survival Mode

What is the LIFO principle in a stack?

Answer: LIFO (Last In, First Out) means the element inserted last into the stack is the first one removed. Push adds to the top and pop removes from the same top. (2 marks) Result: In LIFO, the most recently pushed element is the first element popped.

Key Points

  • LIFO means Last In, First Out (2 marks)
  • Push adds at top and pop removes from top
Q52MUnit 3 — Queue
Core Concept

Name two applications of a queue.

Answer: Applications of a queue include print spooler, CPU or task scheduling, BFS traversal and buffering. Any two are sufficient: print spooler keeps print jobs in arrival order, and CPU scheduling keeps ready tasks in FIFO order. (1 mark each) Result: Print spooler and CPU or task scheduling are two standard queue applications.

Key Points

  • Print spooler (1 mark)
  • CPU or task scheduling (1 mark)
  • Also acceptable: BFS traversal, buffering
Q17MUnit 1 — classification (linear / non-linear, static / dynamic)
Survival Mode

Explain classification of data structures into linear/non-linear and static/dynamic. Also explain Big O notation with examples of O(1), O(n), O(log n), and O(n²).

Concept / Given Data: Data structures are systematically classified based on their memory layout and structural relationships among data elements. This classification enables computer scientists and engineers to select the optimal design for memory utilization and execution speed.

Key Formula / Principle: Time Complexity T(n)=O(f(n)) where lim⁡n→∞∣T(n)f(n)∣=K<∞\text{Time Complexity } T(n) = O(f(n)) \text{ where } \lim_{n \to \infty} \left|\frac{T(n)}{f(n)}\right| = K < \infty

Step-by-Step Solution / Working:

  1. Linear Data Structures: Elements are arranged sequentially or linearly, where each element is connected to its previous and next element. Examples include Arrays, Linked Lists, Stacks, and Queues. Accessing elements can be done in a single sequential pass.

  2. Non-Linear Data Structures: Elements are arranged in a hierarchical or interconnected network where data items are not arranged sequentially. Examples include Trees (hierarchical relationships) and Graphs (multi-path networks).

  3. Static Data Structures: Memory allocation is fixed at compile-time and cannot be altered during runtime. Example: Standard arrays in C. Once declared as intarr[100]int arr[100], the size cannot be dynamically grown.

  4. Dynamic Data Structures: Memory is allocated and deallocated dynamically at runtime using heap memory and pointers. Example: Linked lists and dynamic arrays (like Python lists).

  5. Big O Notation & Examples: Big O describes the upper bound of an algorithm's growth rate.

    • O(1)O(1) (Constant Time): Execution time is independent of input size nn. Example: Accessing an array element by its index, arr[i]arr[i].
    • O(log⁡n)O(\log n) (Logarithmic Time): Search space halves at every step. Example: Binary Search on a sorted array.
    • O(n)O(n) (Linear Time): Execution time grows linearly with input size. Example: Linear search or traversing an array of size nn.
    • O(n2)O(n^2) (Quadratic Time): Execution time is proportional to the square of the input size. Example: Nested loops in matrix multiplication or Bubble Sort.

Result: Data structures dictate memory efficiency, while Big O notation mathematically guarantees scalability limits. Understanding these classifications is fundamental for algorithmic optimization.

Tip from Examiner: Clearly distinguish between static/dynamic (memory allocation) and linear/non-linear (traversal topology) to secure full marks.

Key Points

  • Linear vs Non-linear structures define sequential vs hierarchical access.
  • Static structures have fixed compile-time size; dynamic structures resize at runtime.
  • Big O notation bounds worst-case algorithm growth.
  • O(1), O(log n), O(n), and O(n²) represent constant, logarithmic, linear, and quadratic complexities.
Q27MUnit 2 — Singly linked list
Survival Mode

Explain a singly linked list. Write the logic/steps for insertion at head and deletion of a node by value.

Concept / Given Data:

A singly linked list is a linear data structure in which each node stores a data element and a pointer to the next node in the sequence. The first node is referenced by an external pointer called headhead, and the last node's nextnext pointer holds NULLNULL, marking the end of the list. Nodes are allocated dynamically using mallocmalloc, so they need not occupy contiguous memory locations. This non-contiguous storage is the fundamental reason linked lists support efficient insertion and deletion without shifting elements, unlike arrays where inserting at position ii requires shifting all subsequent elements by one position.

Key Formula / Principle: Time complexity of insertion at head is $O(1)$ because only two pointer assignments are needed regardless of list length $n$. Deletion by value is $O(n)$ in the worst case because we must traverse the entire list to locate the target node.

Step-by-Step: Insertion at Head

  1. Allocate a new node: new=(struct node ∗)malloc(sizeof(struct node))new = (struct\ node\ *)malloc(sizeof(struct\ node)); assign the value: new->data=valnew\text{->}data = val.
  2. Link the new node to the current first node: new->next=headnew\text{->}next = head.
  3. Update the head pointer: head=newhead = new.

Critical ordering: Step 2 must precede Step 3. If we set head=newhead = new first, the address of the old first node is lost and the rest of the list becomes unreachable (memory leak).

Step-by-Step: Deletion by Value

  1. Check if the list is empty (head=NULLhead = NULL). If so, print 'List is empty' and return.
  2. If the node to be deleted is the head itself (head->data=valhead\text{->}data = val), save the address: temp=headtemp = head; move head forward: head=head->nexthead = head\text{->}next; free the old head: free(temp)free(temp).
  3. For deletion at any other position, initialise two pointers: prev=headprev = head and curr=head->nextcurr = head\text{->}next. Traverse while curr≠NULLcurr \neq NULL and curr->data≠valcurr\text{->}data \neq val, updating prev=currprev = curr and curr=curr->nextcurr = curr\text{->}next in each iteration.
  4. If curr=NULLcurr = NULL after the loop, the value was not found; print an appropriate message and return.
  5. If the value is found, unlink the node: prev->next=curr->nextprev\text{->}next = curr\text{->}next; then release memory: free(curr)free(curr).
Insertion at Head (val = 5):5 | •10 | •20 | NULLDeletion of 10 (by value):5 | •10 | •20 | NULLAfter: prev->next = curr->next (bypasses 10)5 | •20 | NULL

Result: After insertion at head, the new node becomes the first element and all previous nodes shift one position right in logical order. After deletion by value, the target node is removed from the chain and its memory is released, with the predecessor's nextnext pointer now bypassing the deleted node directly to the successor.

Tip from Examiner: In 7-mark answers, always state the time complexity explicitly ($O(1)$ for head-insert, $O(n)$ for delete-by-value) and mention the memory-leak trap (forgetting $free$). Examiners deduct 1–2 marks if the ordering of pointer assignments in head-insertion is not justified. Draw the before/after pointer diagram even if not explicitly asked — it demonstrates understanding and earns presentation marks.

Key Points

  • Node = data field + next pointer; last node's next is NULL
  • Insert at head: new->next = head THEN head = new (order matters to avoid losing list)
  • Delete by value: use prev and curr pointers; handle head deletion as a special case
  • Time complexity: head-insert O(1), delete-by-value O(n) worst case
  • Always call free() after unlinking to prevent memory leaks
Q37MUnit 3 — Stack
Survival Mode

Explain stack operations using an array. Describe push, pop, and peek, and show how a stack checks balanced parentheses.

Concept / Given Data

A Stack is a linear data structure that follows the LIFO (Last In, First Out) principle. All insertion and deletion occur at one end called the top. The three fundamental operations are:

  • push(x): insert element xx at the top.
  • pop(): remove and return the top element.
  • peek(): return the top element without removing it.
Key Principle: top=−1 (empty),top=MAX−1 (full)\text{top} = -1 \text{ (empty)}, \quad \text{top} = \text{MAX}-1 \text{ (full)}

Step-by-Step: Array Implementation in C

  1. Declare int s[MAX], top = -1;
  2. push(x): check if (top == MAX-1) → overflow; else s[++top] = x;
  3. pop(): check if (top == -1) → underflow; else return s[top--];
  4. peek(): check if (top == -1) → underflow; else return s[top];
void push(int x) {
    if (top == MAX-1) { printf("Overflow\n"); return; }
    s[++top] = x;
}
int pop() {
    if (top == -1) { printf("Underflow\n"); return -1; }
    return s[top--];
}

Application: Balanced Parentheses Check

Algorithm:

  1. Scan the expression left to right.
  2. If character is an opener (, {, [ → push it.
  3. If character is a closer ), }, ] → pop the top; if the popped opener does not match the closer → unbalanced.
  4. After scanning, if the stack is empty → balanced; otherwise → unbalanced.

Trace for ({[]}):

Step Char Action Stack (top→)
1 ( push (
2 { push ( {
3 [ push ( { [
4 ] pop [ ✓ ( {
5 } pop { ✓ (
6 ) pop ( ✓ (empty)

Stack is empty → Balanced ✓

Result: The stack-based algorithm runs in O(n)O(n) time and O(n)O(n) worst-case space. A Python traceback is a real-world call stack where each frame is an activation record pushed on entry and popped on return.

Tip from Examiner: Always mention the overflow/underflow conditions explicitly (1 mark each). For the parentheses trace, show at least 4 steps in a table — examiners award 2 marks for a correct trace. Common mistake: forgetting to check if the stack is empty before popping on a closer.

Key Points

  • Stack is LIFO: push/pop/peek all operate at the top end only
  • Overflow when top == MAX-1; underflow when top == -1
  • Balanced parentheses: push openers, pop on closers, verify match, final stack must be empty
  • Time complexity O(n), worst-case space O(n) for parentheses check
  • Python traceback is a real-world example of a function call stack
Q47MUnit 4 — Linear search
Survival Mode

Compare linear search and binary search. Trace binary search for key 35 in [10, 20, 30, 35, 40, 50].

Linear and binary search are the two fundamental algorithms for locating an element in a collection. Linear search scans each element in sequence, giving O(n)O(n) time and working on data in any order. Binary search requires a sorted array and uses divide and conquer: it compares the key with the middle element and discards one half, giving O(log⁡n)O(\log n) time.

Feature Linear search Binary search
Data order Any order Must be sorted
Access Sequential Random access by index
Best case O(1)O(1) O(1)O(1)
Worst case O(n)O(n) O(log⁡n)O(\log n)
Space O(1)O(1) O(1)O(1) iterative

Binary search suits large sorted arrays, databases and dictionaries, while linear search is the only option for linked lists, unsorted files and small collections where the cost of sorting would exceed the saving.

Key Principle: mid=low+⌊(high−low)/2⌋mid = low + \lfloor(high - low) / 2\rfloor

Trace for key 35 in [10, 20, 30, 35, 40, 50]:

  1. Initial: low=0,high=5low=0, high=5. mid=0+⌊(5−0)/2⌋=2mid = 0 + \lfloor(5-0)/2\rfloor = 2. a[2]=30a[2]=30. Since 30<3530 < 35, set low=mid+1=3low = mid + 1 = 3.
  2. Iteration 2: low=3,high=5low=3, high=5. mid=3+⌊(5−3)/2⌋=4mid = 3 + \lfloor(5-3)/2\rfloor = 4. a[4]=40a[4]=40. Since 40>3540 > 35, set high=mid−1=3high = mid - 1 = 3.
  3. Iteration 3: low=3,high=3low=3, high=3. mid=3+⌊(3−3)/2⌋=3mid = 3 + \lfloor(3-3)/2\rfloor = 3. a[3]=35a[3]=35. Match found at index 3.

Result: The target 35 is found at index 3 in three comparisons, while linear search would have needed four. Binary search is therefore far more efficient on large sorted data.

Tip from Examiner: Always verify the array is sorted before applying binary search, and tabulate low, high and mid for every step — otherwise the trace marks are lost.

Key Points

  • Linear search is O(n)O(n) and works on unsorted lists
  • Binary search is O(log⁡n)O(\log n) and needs sorted data
  • Each step halves the search space
  • Key 35 found at index 3
Q57MUnit 5 — Binary tree
Survival Mode

Explain binary tree terminology: root, leaf, height, and level. Also describe inorder, preorder, and postorder traversals with a small example.

A binary tree is a hierarchical data structure where each node has at most two children, referred to as the left child and the right child.

Terminology:

  1. Root: The topmost node of the tree, having no parent.
  2. Leaf: A node with no children (degree 0).
  3. Level: The distance of a node from the root. The root is at level 00, and its children are at level 11.
  4. Height: The number of edges on the longest path from the root to a leaf. A single-node tree has height 00.
Traversal Principles:
  • Inorder (Left-Root-Right): Visits nodes in non-decreasing order for a BST.
  • Preorder (Root-Left-Right): Useful for cloning a tree.
  • Postorder (Left-Right-Root): Useful for deleting a tree or evaluating expressions.

Consider a tree with root AA, left child BB, and right child CC.

Traversal Sequence
Inorder B,A,CB, A, C
Preorder A,B,CA, B, C
Postorder B,C,AB, C, A
ABC

In summary, these traversals are fundamental for tree processing. Inorder traversal of a Binary Search Tree (BST) always yields sorted data, which is critical for database indexing applications. Preorder and postorder are essential for recursive tree operations where the parent-child relationship must be maintained during processing. The height of the tree determines the time complexity of search operations, which is O(h)O(h).

Tip from Examiner: Always remember that for a tree with $n$ nodes, there are exactly $n-1$ edges. Do not confuse height with depth; height is measured in edges, while depth is often measured in nodes.

Key Points

  • Root is the unique starting node with no parent.
  • Leaf nodes represent the termination of branches.
  • Inorder traversal is Left→Root→RightLeft \to Root \to Right.
  • Preorder traversal is Root→Left→RightRoot \to Left \to Right.
  • Postorder traversal is Left→Right→RootLeft \to Right \to Root.
Q2(a)7MUnit 2 — Singly linked list
Survival ModePredicted

(a) Explain singly linked list, doubly linked list, and circular linked list. Compare them on structure, traversal, and applications.

A linked list is a linear data structure where elements are stored in nodes, each containing data and a pointer to the next node.

1. Singly Linked List: Each node points only to the next node. Traversal is unidirectional from head to tail. It is memory-efficient but requires O(n)O(n) time to access the previous node.

2. Doubly Linked List: Each node contains two pointers: nextnext and prevprev. This allows bidirectional traversal. It is ideal for applications like browser history (back/forward buttons) and LRU caches.

3. Circular Linked List: The last node points back to the head, forming a ring. This is perfect for round-robin scheduling or music playlists where the track list repeats.

Comparison Table:
Feature Singly Doubly Circular
Pointers 1 (next) 2 (next, prev) 1 (next)
Traversal Forward Bidirectional Cyclic
Memory Low High Low
Application Simple Stacks Browser History Round-Robin

Structural Analysis: In a singly list, the structure is defined as struct node { int data; struct node *next; };. In a doubly list, we add struct node *prev;. The circular list maintains the same structure as a singly list but sets the final node's next pointer to head instead of NULL.

Traversal and Complexity: For all types, searching takes O(n)O(n) time. However, insertion at a known position is O(1)O(1) for all, provided we have the pointer. Doubly linked lists offer superior flexibility for deletion, as we can access the predecessor directly without traversing from the head. Circular lists eliminate the need for NULL checks, simplifying cyclic processing logic.

Result: The choice of list depends on the trade-off between memory overhead (doubly) and traversal requirements (circular/singly).

Tip from Examiner: Always mention that the primary difference lies in the pointer overhead. A common mistake is forgetting that circular lists can be either singly or doubly linked.

Key Points

  • Singly linked list uses one pointer for forward traversal.
  • Doubly linked list uses two pointers for bidirectional movement.
  • Circular linked list connects the tail back to the head.
  • Memory overhead increases with the number of pointers per node.
  • Choose list type based on traversal direction and deletion needs.
Q2(b)7MUnit 2 — Singly linked list
Core Concept

(b) Describe node structure in a linked list. Write C or Python logic to create a singly linked list, insert a node at tail, and traverse the list.

Node Structure and Singly Linked List Operations

Concept: A linked list is a linear data structure where elements are not stored in contiguous memory locations. Each element, called a Node, consists of two parts: the data field to store the value and the next pointer to store the memory address of the subsequent node. The last node contains NULL in its pointer field.

Node Structure (C): struct Node{int data; struct Node∗ next;};struct\ Node \{ int\ data; \ struct\ Node*\ next; \};

1. Insertion at Tail: To insert at the tail, we traverse the list starting from the head until we reach the node where next == NULL. We then update this pointer to the new node and set the new node's next to NULL.

2. Traversal: Traversal involves starting at the head and visiting each node sequentially by following the next pointer until the pointer becomes NULL.

Implementation Logic:

void insertAtTail(struct Node** head, int val) {
    struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
    newNode->data = val; newNode->next = NULL;
    if (*head == NULL) { *head = newNode; return; }
    struct Node* temp = *head;
    while (temp->next != NULL) temp = temp->next;
    temp->next = newNode;
}

void traverse(struct Node* head) {
    while (head != NULL) {
        printf("%d -> ", head->data);
        head = head->next;
    }
    printf("NULL");
}

Result: The linked list provides dynamic memory allocation, allowing efficient insertion at the tail in O(n)O(n) time complexity, where nn is the number of nodes, as we must traverse to the end.

Tip from Examiner: Always handle the empty list case (`head == NULL`) separately to avoid segmentation faults when dereferencing the pointer during insertion.

Key Points

  • Node contains data and a pointer to the next node.
  • Linked lists use dynamic memory allocation via malloc.
  • Insertion at tail requires O(n) traversal to find the last node.
  • Traversal visits nodes sequentially until NULL is reached.

Section C

7 Marks Each · 6 questions
Q3(a)7MUnit 3 — implementation using array in C/Python
Survival ModePredicted

(a) Explain queue operations enqueue and dequeue using an array. Discuss the problem of linear queue and the idea of a circular queue.

Concept / Given Data

A Queue is a linear data structure that follows the FIFO (First In, First Out) principle. Insertion happens at the rear end and deletion at the front end. The two fundamental operations are:

  • enqueue(x): insert element xx at the rear.
  • dequeue(): remove and return the element at the front.
Key Principle: front=0,  rear=−1 (empty),rear=MAX−1 (full in linear queue)\text{front} = 0,\; \text{rear} = -1 \text{ (empty)}, \quad \text{rear} = \text{MAX}-1 \text{ (full in linear queue)}

Step-by-Step: Linear Queue Array Implementation in C

  1. Declare int q[MAX], front = 0, rear = -1;
  2. enqueue(x): check if (rear == MAX-1) → overflow; else q[++rear] = x;
  3. dequeue(): check if (front > rear) → underflow; else return q[front++];
void enqueue(int x) {
    if (rear == MAX-1) { printf("Queue full\n"); return; }
    q[++rear] = x;
}
int dequeue() {
    if (front > rear) { printf("Queue empty\n"); return -1; }
    return q[front++];
}

Problem with Linear Queue

After several enqueue–dequeue cycles, front advances but the slots before front become permanently wasted. Even if free space exists at the front, the queue reports overflow because rear == MAX-1. This is the wasted-space problem.

Example: With MAX = 5, after enqueue(A), enqueue(B), enqueue(C), dequeue(), dequeue(), we have front = 2, rear = 2. Only slot 2 is occupied, yet rear cannot advance past index 4, so at most 2 more elements can be enqueued instead of 5.

Circular Queue — The Solution

In a circular queue, the array is treated as a ring. The rear wraps around using modulo arithmetic:

rear=(rear+1) mod MAX\text{rear} = (\text{rear} + 1) \bmod \text{MAX} front=(front+1) mod MAX\text{front} = (\text{front} + 1) \bmod \text{MAX}
  • Empty condition: front == rear (with an initial front = 0, rear = -1 convention, or use a count variable).
  • Full condition: (rear + 1) % MAX == front.

This eliminates wasted space and allows the queue to reuse front slots.

Real-World Connect: A print spooler uses a queue — jobs are enqueued in arrival order and dequeued for printing in the same order. CPU task scheduling (Round-Robin) also uses a queue of ready processes.

Result: Linear queue wastes O(n)O(n) space after repeated operations; circular queue reuses all nn slots efficiently with O(1)O(1) enqueue and dequeue.

Tip from Examiner: The question explicitly asks for the *problem* and the *idea* of circular queue — do not just write code. State the wasted-space issue in one sentence, then give the modulo formula. Examiners award 2 marks for the circular queue explanation alone. Common mistake: writing `rear == MAX` instead of `rear == MAX-1` for the full condition in a linear queue.

Key Points

  • Queue is FIFO: enqueue at rear, dequeue at front
  • Linear queue problem: front slots become permanently wasted after dequeue operations
  • Circular queue uses modulo arithmetic: rear = (rear+1) % MAX to wrap around
  • Full condition in circular queue: (rear+1) % MAX == front
  • Print spooler and CPU scheduling are real-world queue applications
Q3(b)7MUnit 3 — function call stack (concept)
Core Concept

(b) Explain stack applications in function call stack and expression evaluation. Convert or evaluate a simple expression using stack concept and describe Polish notation briefly.

Function call stack. Every function call creates an activation record (stack frame) that holds the arguments, the return address, saved registers and local variables. When main calls f, and f calls g, the frames are pushed in order and popped in reverse order, so the structure is LIFO. This is exactly why recursion works: each recursive call keeps its own copy of the parameters, and the deepest call returns first. Running out of stack memory raises a stack-overflow error, which is typical of infinite recursion.

Expression evaluation. A stack evaluates postfix expressions without any brackets. Operands are pushed; when an operator appears, the top two operands are popped, the operation is applied, and the result is pushed back. The final value is the only item left on the stack. Converting infix to postfix uses the shunting-yard rule: send operands straight to the output, push operators, pop an operator when the incoming one has lower or equal precedence, and pop everything on a closing bracket.

Polish notation. In prefix (Polish) form the operator precedes its operands, in infix it sits between them, and in postfix (reverse Polish) it follows them:

Infix Prefix Postfix
A+B +AB AB+
(A+B)*C *+ABC AB+C*

Prefix and postfix need no brackets because the order of the symbols itself encodes precedence.

Evaluation trace: for postfix 5 6 2 + *, push 5, push 6, push 2; the + pops 2 and 6 and pushes 8; the * pops 8 and 5 and pushes 40.

Result: stacks manage call records and evaluate expressions; the postfix expression 5 6 2 + * evaluates to 40.

Tip from Examiner: Show the stack contents after every push and pop in the trace — that is where the marks are. Remember prefix reads operator-first and postfix reads operator-last.
Key Formula: Result\text{Result}

Key Points

  • Activation record holds arguments, return address and locals
  • LIFO order supports nested calls and recursion
  • Postfix evaluation: push operands, pop on operator
  • Infix to postfix uses the shunting-yard rule
  • 5 6 2 + * evaluates to 40
Q4(a)7MUnit 4 — Bubble sort and insertion sort
Survival ModePredicted

(a) Explain bubble sort and insertion sort. Trace bubble sort on [64, 34, 25, 12].

Bubble sort and insertion sort are fundamental sorting algorithms. Bubble sort repeatedly steps through the list, compares adjacent elements, and swaps them if they are in the wrong order. This process repeats until the list is sorted, with the largest elements bubbling to the end. Insertion sort builds the sorted array one item at a time by taking elements from the unsorted portion and inserting them into their correct position within the sorted prefix.

Complexity Comparison: Bubble: O(n2),Insertion: O(n2) worst, O(n) best\text{Bubble: } O(n^2),\qquad \text{Insertion: } O(n^2) \text{ worst, } O(n) \text{ best}

Trace Bubble Sort on [64, 34, 25, 12]:

  • Pass 1: Compare (64,34) →\rightarrow swap [34, 64, 25, 12]. Compare (64,25) →\rightarrow swap [34, 25, 64, 12]. Compare (64,12) →\rightarrow swap [34, 25, 12, 64]. (64 is now fixed).
  • Pass 2: Compare (34,25) →\rightarrow swap [25, 34, 12, 64]. Compare (34,12) →\rightarrow swap [25, 12, 34, 64]. (34 is now fixed).
  • Pass 3: Compare (25,12) →\rightarrow swap [12, 25, 34, 64]. (25 is now fixed).

Result: After 3 passes the array is sorted as [12, 25, 34, 64]. Bubble sort is stable, so it preserves the relative order of equal elements, which matters in ranking applications where a secondary criterion must be kept. Insertion sort is also stable but adaptive: on a nearly sorted list its inner loop shifts very few elements, so it approaches linear time, whereas bubble sort still performs a full pass unless an early-exit flag is added.

Tip from Examiner: Insertion sort is faster than bubble sort in practice because it performs fewer swaps, especially for nearly sorted data. Show each pass of the trace separately to earn the step marks.

Key Points

  • Bubble sort swaps adjacent elements repeatedly
  • Insertion sort inserts into a growing sorted prefix
  • Both are O(n2)O(n^2) average, insertion sort is O(n)O(n) best
  • Both are stable
  • Insertion sort is adaptive and faster in practice
Q4(b)7MUnit 4 — Quick Sort and Selection Sort
Core Concept

(b) Explain selection sort and merge sort. Compare them on working principle, time complexity, and suitability.

Selection sort finds the minimum element in the unsorted part and places it at the front of that part. It always makes O(n2)O(n^2) comparisons regardless of the input, performs at most n−1n-1 swaps, and is usually not stable because equal keys may be exchanged.

Merge sort uses divide and conquer: split the array into two halves, sort each half recursively, then merge the two sorted halves. The merge compares the front elements of both halves, copies the smaller to the output and advances that pointer; when one half is exhausted the remainder is copied. Merging takes O(n)O(n) time, so the recurrence T(n)=2T(n/2)+O(n)T(n)=2T(n/2)+O(n) solves to O(nlog⁡n)O(n\log n) by the master theorem.

Feature Selection sort Merge sort
Principle Select minimum, place at front Divide, recurse, merge
Best case O(n2)O(n^2) O(nlog⁡n)O(n\log n)
Worst case O(n2)O(n^2) O(nlog⁡n)O(n\log n)
Extra space O(1)O(1) O(n)O(n)
Stable Usually no Yes
Suitability Tiny arrays, low memory Large data, stable output

Why the difference matters. Selection sort performs exactly the same scan of the unsorted suffix no matter how the input is arranged, so sorting an already ordered array is just as expensive as sorting a reversed one. Merge sort pays an extra array of size n, but its predictable logarithmic growth makes it the right choice once the input grows beyond a few dozen items. Stability is the deciding factor when records carry a second key, such as sorting students by name while keeping their original roll-number order within equal names; merge sort preserves that order and selection sort generally does not.

Result: selection sort is simple and memory-light but quadratic, while merge sort is asymptotically faster and stable at the cost of an extra array.

Tip from Examiner: State the recurrence for merge sort and name the master theorem — that is worth a full mark. Also mention that merge sort is preferred for linked lists because no random access is needed.
Key Formula: Result\text{Result}

Key Points

  • Selection sort: minimum to front, O(n2)O(n^2), in place
  • Merge sort: divide, conquer, merge
  • Merge costs O(n)O(n), giving O(nlog⁡n)O(n\log n)
  • Merge sort is stable but needs O(n)O(n) space
  • Selection sort is good for tiny arrays
Q5(a)7MUnit 5 — Binary Search Tree
Survival ModePredicted

(a) Explain Binary Search Tree insertion and search. Construct a BST by inserting 50, 30, 70, 20, 40 and show inorder traversal.

A Binary Search Tree (BST) is a binary tree in which, for every node NN, all values in the left subtree are less than NN and all values in the right subtree are greater than NN. This ordering makes searching, insertion and deletion logarithmic on a balanced tree.

Insertion and search. Search starts at the root: if the key equals the node, report success; if it is smaller, move left; otherwise move right; stop at a null pointer. Insertion performs the same walk and attaches the new node at the null position. Deletion has three cases: a leaf is removed directly, a node with one child is replaced by that child, and a node with two children is replaced by its inorder successor, the smallest value in its right subtree.

Key Principle: O(h), where h is the height; balanced: h=log⁡2nO(h)\text{, where } h \text{ is the height; balanced: } h = \log_2 n

Construction (insert 50, 30, 70, 20, 40):

  1. 50 becomes the root.
  2. 30<5030 < 50, so it becomes the left child of 50.
  3. 70>5070 > 50, so it becomes the right child of 50.
  4. 20<5020 < 50 and 20<3020 < 30, so it becomes the left child of 30.
  5. 40<5040 < 50 and 40>3040 > 30, so it becomes the right child of 30.
5030702040

Inorder traversal: following left-root-right gives 20,30,40,50,7020, 30, 40, 50, 70, which is ascending and confirms the BST property.

Result: the constructed tree stores the keys in valid BST order, and its inorder traversal is sorted. A skewed insertion sequence would give height h=nh=n and linear cost, which self-balancing trees such as AVL prevent.

Tip from Examiner: The worst-case cost is $O(n)$ for a skewed tree, not $O(\log n)$. Always check that the inorder traversal is strictly ascending — it proves the BST property.

Key Points

  • BST property: left < root < right
  • Search and insert follow the same path
  • Deletion uses the inorder successor
  • Inorder traversal is sorted
  • Skewed trees degrade to O(n)O(n)
Q5(b)7MUnit 5 — adjacency list representation
Core Concept

(b) Explain graph representation using adjacency list. Describe BFS and DFS and trace either BFS or DFS on a small graph.

An adjacency list is a collection of unordered lists used to represent a finite graph. Each vertex VV in the graph is associated with a list of its adjacent vertices. For a graph with VV vertices and EE edges, the space complexity is O(V+E)O(V+E), making it highly efficient for sparse graphs compared to an adjacency matrix which requires O(V2)O(V^2) space.

Graph Representation Principle: Adj[u]={v∣(u,v)∈E}Adj[u] = \{v \mid (u, v) \in E\}

Breadth-First Search (BFS) explores the graph level by level using a queue. It starts at a source node, visits all its immediate neighbors, and then moves to the next level. Depth-First Search (DFS) explores as far as possible along each branch before backtracking, typically using a stack or recursion.

Trace of BFS on graph (A-B, A-C, B-D, C-E):

  1. Start at AA. Queue: [A][A]. Visited: {A}\{A\}.
  2. Dequeue AA. Enqueue neighbors B,CB, C. Queue: [B,C][B, C]. Visited: {A,B,C}\{A, B, C\}.
  3. Dequeue BB. Enqueue neighbor DD. Queue: [C,D][C, D]. Visited: {A,B,C,D}\{A, B, C, D\}.
  4. Dequeue CC. Enqueue neighbor EE. Queue: [D,E][D, E]. Visited: {A,B,C,D,E}\{A, B, C, D, E\}.
  5. Dequeue DD, then EE. Queue empty. Final BFS order: A→B→C→D→EA \to B \to C \to D \to E.
ABCDE

Result: The adjacency list provides an optimal way to store sparse connections. BFS ensures the shortest path in unweighted graphs, while DFS is useful for cycle detection and topological sorting.

Tip from Examiner: Always mention the space complexity $O(V+E)$ for adjacency lists. In exams, if asked for a trace, clearly show the queue/stack state at every step to secure full marks.

Key Points

  • Adjacency list uses O(V+E)O(V+E) space.
  • BFS uses a queue for level-order traversal.
  • DFS uses a stack for depth-first exploration.
  • BFS is ideal for shortest path in unweighted graphs.
  • DFS is effective for pathfinding and cycle detection.