Welcome to Edugrown – Your Learning Partner EduGrown
🕑 Aaj ke free content khatam — ye page khula rahega, naya content kal se. Login karein →
← Back to UG & PG Content
Exam Papers

Btech 3rd Sem Data Structures Solved Paper December 2024 (RGPV CS-303)

RGPV University (RGPV) · MP · Engineering (B.Tech / B.E.) · Computer science · 2nd Year · Semester 3 · 7 views

Advertisement

Btech 3rd Sem — Data Structures Solved Paper

RGPV Bhopal · CS/CT/CO-303 · Examination: December 2024
B.Tech III SemesterGrading System (GS)Time: 3 HoursMax Marks: 70
Exam instructions:
  • Attempt any five questions. All questions carry equal marks (14 each).
  • Marks of every part are shown beside the question; answers are written to that length: definition → working/algorithm → example/diagram → conclusion.
  • In case of any doubt, the English version of the question is final.

Question-wise topics

Q.No.Topics asked
Q1Traversing a singly linked list; classification of data structures
Q2Arrays vs linked lists as ADTs; dynamic vs static arrays
Q3Reverse a stack using one extra stack; circular queue insert/delete
Q4Push/pop on linked stack; deque and its operations
Q5Expression tree and traversals; BST creation and deletion
Q6AVL single and double rotations; DFS vs BFS
Q7MST and Prim's algorithm; quick sort simulation
Q8Binary search for 36; short notes: hashing & indexing, heap sort, red-black tree
Question 1
Q.1 (a)7 Marks
Write an algorithm for traversing nodes in a single linked list? Explain with an example.
Answer
Traversing a linked list means visiting (processing) every node exactly once, starting from START and following the NEXT pointers until NULL.

Algorithm TRAVERSE(START)

  1. Set PTR = START.
  2. Repeat steps 3 and 4 while PTR ≠ NULL:
  3.    Apply PROCESS to PTR→INFO (e.g. print it).
  4.    Set PTR = PTR→NEXT.
  5. Exit.
void traverse(struct node *start) {
    struct node *ptr = start;
    while (ptr != NULL) {
        printf("%d -> ", ptr->info);   /* PROCESS */
        ptr = ptr->next;
    }
    printf("NULL\n");
}

Example

START15253545NULL
StepPTR points toOutput so far
1node 1515
2node 2515 25
3node 3515 25 35
4node 4515 25 35 45
5NULL → stop15 25 35 45

Counting nodes or summing values uses the same loop (COUNT = COUNT + 1 or SUM = SUM + INFO). Time complexity O(n), extra space O(1).

Q.1 (b)7 Marks
Define data structures. Classify different types of data structures.
Answer
A data structure is a logical or mathematical model for organising and storing data in memory so that operations (insertion, deletion, searching, traversal) can be performed efficiently. Data structure = organised data + allowed operations.
Data StructurePrimitiveNon-Primitiveint, float, char, pointerLinearNon-LinearArray, Stack, Queue, Linked ListTree, Graph
Classification of data structures

1. Primitive data structures

Basic types directly supported by the machine/language: int, float, char, double, boolean, pointer. They hold a single value.

2. Non-primitive data structures

Derived from primitive types; they store a collection of values.

  • Linear: elements form a sequence; each element has a unique predecessor and successor. Examples: Array (fixed size, contiguous), Linked list (nodes connected by pointers), Stack (LIFO), Queue (FIFO).
  • Non-linear: an element may be connected to many others, forming a hierarchy or network. Examples: Tree (hierarchical, e.g. BST, heap), Graph (network of vertices and edges).

Other classifications

  • Static vs Dynamic: static size fixed at compile time (array); dynamic size changes at run time (linked list, dynamic array).
  • Homogeneous vs Heterogeneous: same type elements (array) vs different types (structure / record).
  • Sequential vs Linked storage: contiguous memory (array) vs scattered nodes with pointers (list, tree).
LinearNon-linear
Data arranged sequentiallyData arranged hierarchically / as a network
Single levelMultiple levels
Traversed in a single runNeeds special traversals (inorder, BFS, DFS)
Array, stack, queue, listTree, graph, heap
Question 2
Q.2 (a)7 Marks
Compare and contrast the characteristics of arrays and linked lists as abstract data types.
Answer

Both arrays and linked lists implement the List ADT (ordered collection with operations get(i), insert, delete, search, traverse), but their storage and performance differ.

10203040
Array: contiguous cells, index 0–3
START10203040NULL
Linked list: nodes joined by pointers
CharacteristicArrayLinked list
Memory allocationContiguous block, usually static (compile time)Non-contiguous nodes, dynamic (run time, malloc)
SizeFixed; must be declared in advanceGrows / shrinks as needed
Access to k-th elementRandom access O(1): base + k × sizeSequential access O(n) from head
Insertion / deletionO(n) — elements must be shiftedO(1) once the position (pointer) is known
Extra memoryNone per element (may waste unused slots)Extra pointer field in every node
SearchLinear O(n); binary search O(log n) if sortedLinear O(n) only (no binary search)
Cache localityExcellent (contiguous)Poor (scattered nodes)
Memory wasteUnused declared slotsPointer overhead
Best suited forFrequent access by index, fixed-size data, matricesFrequent insertions/deletions, unknown size, stacks/queues
Choose an array when fast indexed access matters and the size is known; choose a linked list when the size changes often and insertions/deletions dominate.
Q.2 (b)7 Marks
Describe the concept of a dynamic array and how it differs from a static array in terms of memory management and flexibility.
Answer
A static array has a size fixed at compile time (e.g. int a[100];) and is allocated on the stack or in static memory. A dynamic array is allocated on the heap at run time and can be resized when it becomes full — e.g. C's malloc/realloc, C++ std::vector, Java ArrayList, Python list.

How a dynamic array grows

  • It keeps three things: pointer to the data block, current size (number of elements) and capacity (allocated slots).
  • When size = capacity and a new element is added, a larger block (usually double the capacity) is allocated, old elements are copied and the old block is freed.
  • Because doubling happens rarely, appending is amortised O(1) (total copying for n appends ≤ 2n).
int cap = 2, size = 0;
int *a = (int *)malloc(cap * sizeof(int));

void append(int x) {
    if (size == cap) {                     /* full: grow */
        cap = cap * 2;
        a = (int *)realloc(a, cap * sizeof(int));
    }
    a[size++] = x;
}
/* ... free(a) when no longer needed */

Appending 10, 20, 30, 40, 50: capacity 2 → 4 (at 30) → 8 (at 50).

BasisStatic arrayDynamic array
Allocation timeCompile timeRun time (heap)
SizeFixed, cannot changeCan grow or shrink (realloc)
Memory managementAutomatic (freed when scope ends)Programmer must free (or garbage collector)
Memory usageMay waste space or overflowAllocates as needed; some spare capacity
FlexibilityLow — size must be known in advanceHigh — size decided by data at run time
AccessO(1) random accessO(1) random access (still contiguous)
Insertion at endO(1) until full, then impossibleAmortised O(1); O(n) when resizing
Exampleint a[50];malloc/realloc, vector, ArrayList
Question 3
Q.3 (a)7 Marks
Write an algorithm which reverses the order of elements on stack using one additional stack and some additional variables.
Answer

Let S be the given stack with n elements and T an empty auxiliary stack; variables X, I, J. The idea: in round I, take the current top X of S, park the elements below it that are not yet reversed in T, put X down, and bring the parked elements back. After round I, the I lowest positions of S hold the reversed elements.

Algorithm REVERSE(S, n)

  1. Repeat for I = 1 to n:
  2.    X = POP(S).
  3.    Repeat for J = 1 to n − I: PUSH(T, POP(S)). [move the unreversed elements to T]
  4.    PUSH(S, X). [X goes to its final position]
  5.    Repeat while T is not empty: PUSH(S, POP(T)).
  6. Exit.
void reverse(Stack *S, int n) {
    Stack T; init(&T);
    for (int i = 1; i <= n; i++) {
        int x = pop(S);
        for (int j = 1; j <= n - i; j++)
            push(&T, pop(S));
        push(S, x);
        while (!isEmpty(&T))
            push(S, pop(&T));
    }
}

Trace — S (bottom → top) = 10 20 30 40

RoundActionS (bottom → top) after roundT
Start—10 20 30 40—
i = 1x = 40; move 3 element(s) to T, push x, move back40 10 20 30empty
i = 2x = 30; move 2 element(s) to T, push x, move back40 30 10 20empty
i = 3x = 20; move 1 element(s) to T, push x, move back40 30 20 10empty
i = 4x = 10; move 0 element(s) to T, push x, move back40 30 20 10empty
Final S (bottom → top) = 40 30 20 10 — top is now 10, i.e. the order is reversed. Time O(n²) element moves; extra space: one stack + variables X, I, J.
Q.3 (b)7 Marks
Explain the addition and deletion operations performed on a circular queue with necessary algorithms.
Answer
A circular queue is a queue stored in an array Q[0 … MAX − 1] in which the last position is connected back to the first: after Q[MAX − 1] comes Q[0]. It removes the drawback of a linear queue where space freed at the front cannot be reused.
  • Next position: (i + 1) % MAX.
  • Empty: FRONT = −1.
  • Full: (REAR + 1) % MAX = FRONT.

Algorithm CQINSERT(Q, MAX, FRONT, REAR, ITEM)

  1. If (REAR + 1) % MAX = FRONT → print “Overflow” and exit.
  2. If FRONT = −1 then set FRONT = REAR = 0;
  3. else set REAR = (REAR + 1) % MAX.
  4. Q[REAR] = ITEM.
  5. Exit.

Algorithm CQDELETE(Q, MAX, FRONT, REAR)

  1. If FRONT = −1 → print “Underflow” and exit.
  2. ITEM = Q[FRONT].
  3. If FRONT = REAR then set FRONT = REAR = −1 (queue becomes empty);
  4. else set FRONT = (FRONT + 1) % MAX.
  5. Return ITEM.

Example (MAX = 5)

OperationEffectFRONTREARArray
Initial—−1−1[ _ _ _ _ _ ]
Insert 10rear = 0, front = 000[10 _ _ _ _]
Insert 20, 30, 40rear = 1, 2, 303[10 20 30 40 _]
Deletereturns 10, front = 113[ _ 20 30 40 _]
Insert 50rear = 414[ _ 20 30 40 50]
Insert 60rear = (4 + 1) % 5 = 0 — wraps around10[60 20 30 40 50]
Insert 70(0 + 1) % 5 = 1 = front → Overflow10full
Insertion at 60 reuses slot 0 freed by the deletion — no space is wasted. Both operations are O(1).
Question 4
Q.4 (a)7 Marks
Write an algorithm for Push and Pop operations on Stack using linked list.
Answer
In the linked stack every element is a node [INFO | LINK]; TOP points to the most recently pushed node. All operations happen at the TOP (beginning of the list).

In the linked representation each stack element is a node; TOP points to the first node. PUSH and POP are done at the beginning of the list, so both are O(1) and there is no fixed size (overflow only when memory is exhausted).

TOP302010NULL
Stack after push 10, 20, 30 (30 is on top)

Algorithm PUSH(TOP, ITEM)

  1. Allocate a new node NEW; if allocation fails → print “Overflow” and exit.
  2. NEW→INFO = ITEM.
  3. NEW→LINK = TOP.
  4. TOP = NEW.
  5. Exit.

Algorithm POP(TOP)

  1. If TOP = NULL → print “Underflow” and exit.
  2. ITEM = TOP→INFO; TEMP = TOP.
  3. TOP = TOP→LINK.
  4. Free TEMP; return ITEM.
  5. Exit.
#include <stdio.h>
#include <stdlib.h>

struct node {
    int data;
    struct node *next;
};
struct node *top = NULL;

void push(int x) {
    struct node *t = (struct node *)malloc(sizeof(struct node));
    if (t == NULL) { printf("Stack Overflow (heap full)\n"); return; }
    t->data = x;
    t->next = top;      /* new node points to old top */
    top = t;            /* new node becomes top */
}

int pop(void) {
    if (top == NULL) { printf("Stack Underflow\n"); return -1; }
    struct node *t = top;
    int x = t->data;
    top = top->next;
    free(t);
    return x;
}

int main(void) {
    push(10); push(20); push(30);
    printf("Popped %d\n", pop());
    printf("Popped %d\n", pop());
    return 0;
}

Output: Popped 30, Popped 20.

Q.4 (b)7 Marks
What is a DeQueue? Explain its operation with example.
Answer
A DeQueue (double-ended queue) is a linear list in which elements can be inserted and deleted at both ends — FRONT and REAR. It can behave as a stack and as a queue.

Types

  • Input-restricted deque: insertion only at one end (rear), deletion at both ends.
  • Output-restricted deque: deletion only at one end (front), insertion at both ends.

Operations (circular array, MAX size)

OperationAlgorithm step
insertFront(x)If full → overflow. If empty, front = rear = 0; else front = (front − 1 + MAX) % MAX. Q[front] = x.
insertRear(x)If full → overflow. If empty, front = rear = 0; else rear = (rear + 1) % MAX. Q[rear] = x.
deleteFront()If empty → underflow. x = Q[front]; if front = rear then empty (−1) else front = (front + 1) % MAX.
deleteRear()If empty → underflow. x = Q[rear]; if front = rear then empty (−1) else rear = (rear − 1 + MAX) % MAX.
getFront / getRear / isEmpty / isFullInspect without changing

Example

OperationDeque (front … rear)
insertRear(10)10
insertRear(20)10 20
insertFront(5)5 10 20
insertFront(1)1 5 10 20
deleteRear() → 201 5 10
deleteFront() → 15 10
Applications: undo-redo lists, palindrome checking, sliding-window maximum, work-stealing job schedulers. All operations are O(1).
Question 5
Q.5 (a)7 Marks
Construct an expression tree for the expression (a + b*c) + ((d*e + f)*g). Apply inorder, preorder and postorder traversals on tree.
Answer

In an expression tree leaves are operands and internal nodes are operators; each operator node's children are its operands. The operator applied last becomes the root.

  1. The last operator evaluated is the middle “+” → root.
  2. Left operand (a + b*c): “+” with children a and (b*c).
  3. Right operand ((d*e + f)*g): “*” with children (d*e + f) and g; (d*e + f) is “+” with children (d*e) and f.
a+b*c+d*e+f*g
Expression tree
TraversalOrderResult
InorderL N Ra + b * c + d * e + f * g (infix; with brackets: (a + b*c) + ((d*e + f)*g))
PreorderN L R+ + a * b c * + * d e f g (prefix / Polish)
PostorderL R Na b c * + d e * f + g * + (postfix / reverse Polish)
Preorder: + + a * b c * + * d e f g   Postorder: a b c * + d e * f + g * +
Q.5 (b)7 Marks
Create a binary search tree for the following numbers 45, 26, 10, 60, 70, 30, 40. Start from an empty binary search tree. Delete keys 10, 60 and 45 one after the other and show the trees at each stage.
Answer

Insertion

KeyPath comparedInserted as
45tree emptyroot
2645left of 45
1045 → 26left of 26
6045right of 45
7045 → 60right of 60
3045 → 26right of 26
4045 → 26 → 30right of 30

Deletion (two-children case uses the inorder successor)

10263040456070BST after inserting 45, 26, 10, 60, 70, 30, 40
263040456070After deleting 10
10 is a leaf — simply remove it.
2630404570After deleting 60
60 has one child (70) — link 60's parent directly to 70.
26304070After deleting 45
45 has two children — replace it by its inorder successor 70 (smallest key in the right subtree), then delete 70 from its old place.

If the inorder predecessor is used instead for 45, the root becomes 40 (largest key in the left subtree) — also correct.

Final BST: root 70 with left subtree 26 (right child 30 → right child 40); inorder 26, 30, 40, 70.
Question 6
Q.6 (a)7 Marks
Describe the algorithms used to perform single and double rotation on AVL tree.
Answer
An AVL tree (Adelson-Velsky and Landis, 1962) is a height-balanced binary search tree in which, for every node, the balance factor BF = height(left subtree) − height(right subtree) is −1, 0 or +1. Its height is always O(log n), so search, insertion and deletion take O(log n).

After an insertion/deletion, BF of some node may become +2 or −2; balance is restored by rotations at the nearest unbalanced ancestor A. The four cases depend on where the new node was inserted:

1. LL rotation (single right rotation)

New node inserted in the left subtree of the left child of A. Rotate right at A: the left child B becomes the root of the subtree, A becomes B's right child, and B's old right subtree becomes A's left subtree.

102030Before (BF of 30 = +2)
102030After right rotation at 30

2. RR rotation (single left rotation)

New node inserted in the right subtree of the right child of A. Rotate left at A (mirror of LL).

102030Before (BF of 10 = −2)
102030After left rotation at 10

3. LR rotation (double rotation: left then right)

New node inserted in the right subtree of the left child of A. First left-rotate at the left child B, then right-rotate at A.

102030Before (BF of 30 = +2)
102030Left-rotate at 10
102030Right-rotate at 30

4. RL rotation (double rotation: right then left)

New node inserted in the left subtree of the right child of A. First right-rotate at the right child B, then left-rotate at A.

102030Before (BF of 10 = −2)
102030Right-rotate at 30
102030Left-rotate at 10

Algorithms

struct node *rightRotate(struct node *A) {   /* LL case */
    struct node *B = A->left;
    A->left  = B->right;      /* B's right subtree moves to A */
    B->right = A;
    A->height = 1 + max(h(A->left), h(A->right));
    B->height = 1 + max(h(B->left), h(B->right));
    return B;                 /* B is the new subtree root */
}

struct node *leftRotate(struct node *A) {    /* RR case */
    struct node *B = A->right;
    A->right = B->left;
    B->left  = A;
    A->height = 1 + max(h(A->left), h(A->right));
    B->height = 1 + max(h(B->left), h(B->right));
    return B;
}

/* LR case */  A->left  = leftRotate(A->left);   A = rightRotate(A);
/* RL case */  A->right = rightRotate(A->right); A = leftRotate(A);
CaseBF(A)BF(child)Rotation
LL+2+1 / 0 (left child)Right at A
RR−2−1 / 0 (right child)Left at A
LR+2−1 (left child)Left at child, right at A
RL−2+1 (right child)Right at child, left at A
Single rotations (LL, RR) fix “straight-line” imbalance; double rotations (LR, RL) fix “zig-zag” imbalance. Every rotation is O(1) and preserves the BST order.
Q.6 (b)7 Marks
Differentiate between Depth first search and Breadth First search algorithm.
Answer
BasisBFS (Breadth First Search)DFS (Depth First Search)
StrategyLevel by level — all neighbours firstGoes deep along one path, then backtracks
Data structureQueue (FIFO)Stack (LIFO) / recursion
Shortest pathFinds shortest path (fewest edges) in unweighted graphsDoes not guarantee shortest path
MemoryStores a whole level — more memory for wide graphsStores one path — less memory (O(height))
Traversal treeWide and shortNarrow and deep
Time complexityO(V + E) list / O(V²) matrixO(V + E) list / O(V²) matrix
BacktrackingNot usedUsed
ApplicationsShortest path, peer-to-peer networks, web crawlers, bipartite check, level orderCycle detection, topological sort, connected components, maze / puzzle solving

Example (graph A–B, A–C, B–D, B–E, C–F, E–F): BFS from A = A B C D E F; DFS from A = A B D E F C.

Question 7
Q.7 (a)7 Marks
Define minimum spanning tree. Write down Prim's algorithm to find minimum spanning tree.
Answer
A spanning tree of a connected undirected graph G is a subgraph that is a tree and includes all the vertices of G (it has V − 1 edges and no cycle). A Minimum Spanning Tree (MST) of a weighted graph is a spanning tree whose total edge weight is the minimum among all spanning trees.

Applications: designing least-cost networks (cable, road, electric grid), clustering, approximation of travelling-salesman.

Prim's algorithm

  1. Start with any vertex s; put it in the tree set T. Set key[s] = 0 and key[v] = ∞ for all other vertices.
  2. Repeat until T contains all V vertices:
  3.    Among all edges (u, v) with u ∈ T and v ∉ T, choose the edge with minimum weight.
  4.    Add v and the edge (u, v) to the tree.
  5.    Update key[w] = min(key[w], weight(v, w)) for every neighbour w of v not in T.
  6. Return the V − 1 chosen edges.

Time: O(V²) with an adjacency matrix; O(E log V) with a binary heap (priority queue).

void prim(int G[V][V]) {
    int key[V], parent[V], inMST[V];
    for (int i = 0; i < V; i++) { key[i] = INF; inMST[i] = 0; }
    key[0] = 0; parent[0] = -1;
    for (int c = 0; c < V - 1; c++) {
        int u = minKey(key, inMST);         /* min key vertex not in MST */
        inMST[u] = 1;
        for (int v = 0; v < V; v++)
            if (G[u][v] && !inMST[v] && G[u][v] < key[v]) {
                parent[v] = u;
                key[v] = G[u][v];
            }
    }
}

Example

StepVertices in treeCandidate edgesChosen
100–4(4), 0–1(8)0–4 (4)
20, 44–2(5), 4–1(6), 4–3(7), 0–1(8)4–2 (5)
30, 4, 22–1(3), 4–1(6), 4–3(7), 0–1(8), 2–3(9)2–1 (3)
40, 4, 2, 14–3(7), 2–3(9)4–3 (7)
012344865739
MST (red) — total weight 19
MST: 0–4 (4), 4–2 (5), 2–1 (3), 4–3 (7); cost 19.
Q.7 (b)7 Marks
Sort the following elements using quick sort: 55, 72, 12, 45, 88, 38, 27, 33, 91, 80
Answer

Partition with the first element as pivot: i moves right while a[i] ≤ pivot, j moves left while a[j] > pivot; swap a[i], a[j] while i < j; finally swap the pivot with a[j]. Recurse on both sides.

int partition(int a[], int lb, int ub) {
    int pivot = a[lb], i = lb + 1, j = ub, t;
    while (1) {
        while (i <= ub && a[i] <= pivot) i++;
        while (a[j] > pivot) j--;
        if (i < j) { t = a[i]; a[i] = a[j]; a[j] = t; }
        else break;
    }
    t = a[lb]; a[lb] = a[j]; a[j] = t;      /* pivot to final place */
    return j;
}
void quickSort(int a[], int lb, int ub) {
    if (lb < ub) {
        int p = partition(a, lb, ub);
        quickSort(a, lb, p - 1);
        quickSort(a, p + 1, ub);
    }
}
Sub-arrayPivotSwapsArray after partition (pivot in red)
[0..9]55swap 72 ↔ 33; swap 88 ↔ 27; j crossed i → swap pivot 55 with 3838331245275588729180
[0..4]38swap 45 ↔ 27; j crossed i → swap pivot 38 with 2727331238455588729180
[0..2]27swap 33 ↔ 12; j crossed i → swap pivot 27 with 1212273338455588729180
[6..9]88swap 91 ↔ 80; j crossed i → swap pivot 88 with 8012273338455580728891
[6..7]80j crossed i → swap pivot 80 with 7212273338455572808891

Pass 1: pivot 55; i stops at 72, j stops at 33 → swap; i stops at 88, j stops at 27 → swap; crossed → swap 55 with 38 → [38, 33, 12, 45, 27, 55, 88, 72, 91, 80].

Sorted: 12, 27, 33, 38, 45, 55, 72, 80, 88, 91. Average O(n log n), worst O(n²), in-place, not stable.
Question 8
Q.8 (a)7 Marks
Apply Binary search to search 36 in following list: 21, 12, 36, 32, 38, 23, 56, 83, 92, 5, 10, 15
Answer

Binary search needs a sorted list, so first sort it:

51012152123323638568392   (indices 0 … 11)

low = 0; high = n - 1;
while (low <= high) {
    mid = (low + high) / 2;
    if (a[mid] == key) return mid;
    else if (key < a[mid]) high = mid - 1;
    else low = mid + 1;
}
return -1;
lowhighmida[mid]Decision
01152336 > 23 → search right half: low = 6
61183836 < 38 → search left half: high = 7
6763236 > 32 → search right half: low = 7
77736Found
36 is found at index 7 (8th position in the sorted list) after 4 comparisons. Complexity O(log n).
Q.8 (b)7 Marks
Write short notes: (i) Hashing and Indexing (ii) Heap Sort (iii) Red Black Tree
Answer

(i) Hashing and Indexing

Hashing stores and retrieves records in (nearly) constant time by computing the address directly from the key using a hash function h(k) that maps keys to table indices 0 … m − 1.
  • Hash functions: division h(k) = k mod m (m prime), mid-square, folding, multiplication.
  • Collision: two keys get the same address. Resolution: separate chaining (each slot holds a linked list) or open addressing — linear probing (h + i) mod m, quadratic probing (h + i²) mod m, double hashing (h + i·h₂(k)) mod m.
  • Load factor α = n/m; performance degrades as α → 1 for open addressing.

Example: m = 10, keys 23, 43, 13 with h(k) = k mod 10 → all map to 3. Linear probing places them at 3, 4, 5; chaining stores 23 → 43 → 13 in slot 3.

Indexing is a technique to speed up searching in a large file by keeping a separate, smaller index of (key, address) pairs, much like the index of a book.
  • Primary index: on the ordering key of a sorted file — one entry per block (sparse).
  • Secondary index: on a non-ordering field — one entry per record (dense).
  • Clustering index: on a non-key ordering field.
  • Multilevel index / tree index: an index on the index — implemented by B-trees and B+ trees; search cost O(log n) disk accesses.
  • Indexed sequential (ISAM) files: records stored sequentially plus an index for direct access.

Example: a student file sorted by roll number with an index entry for every 100th record — to find roll 457, look up index entry 400 and scan only that block.

(ii) Heap Sort

Heap sort sorts an array by first building a max-heap and then repeatedly moving the root (largest element) to the end of the array and re-heapifying the remaining part.
  1. BUILD-MAX-HEAP(A): heapify nodes from ⌊n/2⌋ − 1 down to 0 — O(n).
  2. For i = n − 1 down to 1: swap A[0] ↔ A[i] (largest goes to its final place); reduce heap size by 1; HEAPIFY(A, 0) — O(log n) each.

Example: [4, 10, 3, 5, 1] → build max-heap [10, 5, 3, 4, 1] → swap 10 to end [1, 5, 3, 4 | 10] → heapify [5, 4, 3, 1 | 10] → swap [1, 4, 3 | 5, 10] → heapify [4, 1, 3 | 5, 10] → swap [3, 1 | 4, 5, 10] → [1 | 3, 4, 5, 10] → sorted [1, 3, 4, 5, 10].

Time O(n log n) in best, average and worst case; space O(1) (in-place); not stable.

(iii) Red Black Tree

A Red-Black tree is a self-balancing BST with an extra colour bit per node satisfying: (1) every node is red or black; (2) root is black; (3) NIL leaves are black; (4) a red node has only black children; (5) every path from a node to its descendant leaves has the same number of black nodes.
51015203040
A valid Red-Black tree

Height ≤ 2 log₂(n + 1) ⇒ search, insertion, deletion O(log n). Insertion fixes red-red violations by recolouring (uncle red) or rotations (uncle black); it needs at most 2 rotations per insert, which makes it faster to update than an AVL tree. Used in C++ map/set, Java TreeMap, Linux CFS scheduler.

Exam tip: Write the definition first, show every step of the algorithm or working (pass tables, the tree after each step), draw neat diagrams and box the final answer — examiners award step marks.
Advertisement

💬 Comments & Doubts

💭

Abhi tak koi comment nahi

Sabse pehle comment karne wale bano!

Apna comment likhein

Doubt ho ya suggestion — kuch bhi poochh sakte hain. Login zaroori nahi hai.

30 − 3 =

Ye sirf ye confirm karne ke liye hai ki aap robot nahi hain.

Comment publish hone se pehle admin check karta hai.

🔒 Content copy nahi kar sakte