Welcome to Edugrown – Your Learning Partner EduGrown
🕑 Aaj 2 free content aur bacha hai. Login karein →
← Back to UG & PG Content
Exam Papers

Btech 3rd Sem Data Structures Solved Paper June 2023 (RGPV CS-303)

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

Advertisement

Btech 3rd Sem — Data Structures Solved Paper

RGPV Bhopal · CS/CT/CO-303 (GS) · Examination: June 2023
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
Q1Abstract data types; linked list and its operations
Q2Stack vs queue; C program infix → postfix
Q3Circular linked list insert/delete algorithms; BST traversals
Q4AVL tree insertion (12 keys) and deletion of 18, 2, 30
Q5Heap and its operations; merge sort simulation
Q6BFS vs DFS; Kruskal's algorithm
Q7Shell sort simulation; sequential search
Q8Short notes: stack using linked list, indexing, B-tree, priority queue
Question 1
Q.1 (a)7 Marks
What are the different abstract data types? Explain.
Answer
An Abstract Data Type (ADT) is a mathematical model of a data type defined only by its values and the operations allowed on them, without specifying how the data is stored or how the operations are implemented. It separates the what (interface) from the how (implementation).

Example: a user of a Stack ADT only knows push, pop, peek, isEmpty; whether it is implemented by an array or a linked list is hidden (data abstraction and encapsulation).

ADTValuesMain operations
Listordered sequence of elementsinsert, delete, find, get(i), length
Stacksequence with one open end (top) — LIFOpush, pop, peek/top, isEmpty, isFull
Queuesequence with two ends (front, rear) — FIFOenqueue, dequeue, front, isEmpty
Dequeinsert/delete at both endsinsertFront, insertRear, deleteFront, deleteRear
Priority Queueelements with prioritiesinsert, deleteMax/deleteMin
Tree / BSThierarchical nodesinsert, delete, search, traverse
Graphvertices and edgesaddVertex, addEdge, BFS, DFS
Set / Map (Dictionary)unique keys / key–value pairsinsert, delete, search (lookup)

Advantages: implementation can change without affecting user programs, code reuse, easier correctness proofs. Each ADT may have several implementations, e.g. List by array or linked list, Priority Queue by heap.

Q.1 (b)7 Marks
What is a linked list? Explain its operations with examples.
Answer
A linked list is a dynamic linear data structure in which each node stores data and a pointer to the next node. Unlike an array, nodes are not contiguous and the size can grow or shrink at run time.
START102030NULL

Operations (with C fragments)

1. Traversal — visit every node: p = start; while (p != NULL) { printf("%d ", p->data); p = p->next; }

2. Insertion at beginning — t->next = start; start = t; (O(1)). Inserting 5 → 5 → 10 → 20 → 30.

3. Insertion at end — move to last node p, then p->next = t; t->next = NULL; (O(n)). Inserting 40 → 10 → 20 → 30 → 40.

4. Insertion after a given node / at position k — t->next = p->next; p->next = t;

5. Deletion — first node: t = start; start = start->next; free(t);; a node after p: t = p->next; p->next = t->next; free(t);. Deleting 20 → 10 → 30.

6. Searching — compare each node's data with the key until found or NULL (O(n)).

7. Others — counting nodes, reversing the list, concatenation, sorting.

Types

  • Singly linked list (one pointer per node)
  • Doubly linked list (prev and next pointers)
  • Circular linked list (last node points to first)
  • Header linked list (special header node)
Advantages: dynamic size, O(1) insertion/deletion at known position. Disadvantages: extra memory for pointers, no random access (O(n) to reach k-th node).
Question 2
Q.2 (a)7 Marks
Differentiate between the stack and queue.
Answer
Stack — linear list where insertion and deletion occur at one end (top): LIFO. Queue — linear list where insertion occurs at the rear and deletion at the front: FIFO.
BasisStackQueue
PrincipleLIFO — Last In First OutFIFO — First In First Out
Ends usedOne end (TOP) for both insertion and deletionInsertion at REAR, deletion at FRONT
InsertionPUSHENQUEUE
DeletionPOPDEQUEUE
PointersOne pointer: topTwo pointers: front and rear
Empty conditiontop = −1front = −1 (or front > rear)
Full condition (array)top = MAX − 1rear = MAX − 1 (linear) / (rear+1) % MAX = front (circular)
Variants—Circular queue, deque, priority queue
Real-life examplePile of plates, undo buttonTicket counter line, printer queue
ApplicationsRecursion, expression evaluation, backtracking, DFSCPU scheduling, buffering, BFS, I/O requests
302010← topStack: 30 leaves first
100201302345frontrearQueue: 10 leaves first

If 10, 20, 30 are inserted in that order, a stack removes 30 first whereas a queue removes 10 first.

Q.2 (b)7 Marks
Write a ‘C’ program to convert the infix expression to postfix expression.
Answer

Idea: operands go directly to the output; operators wait on a stack until an operator of lower precedence (or a right parenthesis / end of input) arrives.

Algorithm POLISH(Q, P) — infix Q to postfix P using a stack

  1. Push “(” onto STACK and add “)” to the end of Q.
  2. Scan Q from left to right and repeat steps 3–6 for each symbol until the STACK is empty:
  3. If an operand is found, add it to P.
  4. If a left parenthesis is found, push it onto STACK.
  5. If an operator ⊗ is found: (a) repeatedly pop from STACK and add to P each operator on the top which has the same or higher precedence than ⊗ (for right-associative ^/$ only higher); (b) push ⊗ onto STACK.
  6. If a right parenthesis is found: (a) repeatedly pop from STACK and add to P each operator until a left parenthesis is found; (b) remove the left parenthesis (do not add it to P).
  7. Exit.
OperatorPrecedenceAssociativity
^ or $ (exponent)3 (highest)Right to left
*, /, %2Left to right
+, −1 (lowest)Left to right

C program

#include <stdio.h>
#include <ctype.h>
#include <string.h>
#define MAX 100

char stack[MAX];
int top = -1;

void push(char c) { stack[++top] = c; }
char pop(void)    { return stack[top--]; }
char peek(void)   { return stack[top]; }

int prec(char c) {
    if (c == '^' || c == '$') return 3;
    if (c == '*' || c == '/' || c == '%') return 2;
    if (c == '+' || c == '-') return 1;
    return 0;
}

int main(void) {
    char infix[MAX], postfix[MAX];
    int k = 0;
    printf("Enter infix expression: ");
    scanf("%99s", infix);
    for (int i = 0; infix[i] != '\0'; i++) {
        char c = infix[i];
        if (isalnum((unsigned char)c))
            postfix[k++] = c;                     /* operand -> output */
        else if (c == '(')
            push(c);
        else if (c == ')') {
            while (top != -1 && peek() != '(')
                postfix[k++] = pop();
            pop();                                /* discard '(' */
        } else {                                  /* operator */
            while (top != -1 && peek() != '(' &&
                   (prec(peek()) > prec(c) ||
                    (prec(peek()) == prec(c) && c != '^' && c != '$')))
                postfix[k++] = pop();
            push(c);
        }
    }
    while (top != -1) postfix[k++] = pop();
    postfix[k] = '\0';
    printf("Postfix expression: %s\n", postfix);
    return 0;
}

Sample run: input A+(B+D)/E-F*(G+H/K) → output ABD+E/+FGHK/+*-; input A+B-C*D*E$F$G → output AB+CD*EFG$$*-.

Time complexity O(n) — each symbol is pushed and popped at most once.

Question 3
Q.3 (a)7 Marks
Write an algorithm for insert and delete operations in circular linked list.
Answer
A circular linked list is a linked list in which the last node points back to the first node instead of NULL, so the list forms a cycle. It is usually accessed through a pointer to the last node (then last→next is the first node), which makes insertion at both ends O(1).
LAST→10203040last node points back to the first node
  • No NULL link — from any node every other node can be reached.
  • Traversal stops when we come back to the starting node (do … while loop).
  • Uses: round-robin CPU scheduling, circular buffers/queues, multiplayer turn games, repeating playlists.
  • Variants: circular singly linked list and circular doubly linked list.

Algorithm: insert at beginning (LAST pointer)

  1. Create node T; T→info = ITEM.
  2. If LAST = NULL: LAST = T; T→next = T; exit.
  3. T→next = LAST→next (old first).
  4. LAST→next = T. Exit.

Algorithm: insert at end

  1. Insert T at the beginning as above.
  2. LAST = T (the new node becomes the last). Exit.

Algorithm: delete node with key ITEM

  1. If LAST = NULL → underflow, exit.
  2. PREV = LAST, CUR = LAST→next.
  3. Repeat until CUR→info = ITEM or the whole circle is scanned: PREV = CUR, CUR = CUR→next.
  4. If not found → print message, exit.
  5. If CUR = PREV (only node): LAST = NULL.
  6. Else PREV→next = CUR→next; if CUR = LAST then LAST = PREV.
  7. Free CUR. Exit.

Example: start with 10 → 20 → 30 (circular). Insert 5 at beginning → 5 → 10 → 20 → 30 → back to 5; insert 40 at end → … 30 → 40 → back to 5; delete 20 → 5 → 10 → 30 → 40 → back to 5.

All insertions at the ends are O(1) because LAST gives direct access to both the last and the first node; deletion of an arbitrary key is O(n).

Q.3 (b)7 Marks
How a binary search tree is traversed? Explain with a suitable example.
Answer
A Binary Search Tree (BST) is a binary tree in which, for every node, all keys in the left subtree are smaller and all keys in the right subtree are larger than the node's key; both subtrees are also BSTs.

Traversal means visiting every node exactly once. The three depth-first traversals differ in when the root (N) is visited relative to the left (L) and right (R) subtrees:

20304050607080
BST built by inserting 50, 30, 70, 20, 40, 60, 80

Recursive algorithms

void inorder(struct node *t) {      /* L  N  R */
    if (t != NULL) {
        inorder(t->left);
        printf("%d ", t->data);
        inorder(t->right);
    }
}

void preorder(struct node *t) {     /* N  L  R */
    if (t != NULL) {
        printf("%d ", t->data);
        preorder(t->left);
        preorder(t->right);
    }
}

void postorder(struct node *t) {    /* L  R  N */
    if (t != NULL) {
        postorder(t->left);
        postorder(t->right);
        printf("%d ", t->data);
    }
}
TraversalOrderResult for the tree aboveUse
InorderLeft → Root → Right20 30 40 50 60 70 80Gives keys in sorted order for a BST
PreorderRoot → Left → Right50 30 20 40 70 60 80Copying a tree, prefix expression
PostorderLeft → Right → Root20 40 30 60 80 70 50Deleting a tree, postfix expression
Level order (BFS)Level by level using a queue50 30 70 20 40 60 80Printing level-wise

Inorder trace: inorder(50) → inorder(30) → inorder(20) prints 20 → prints 30 → inorder(40) prints 40 → back, print 50 → right subtree gives 60 70 80. Each traversal is O(n) time and O(h) stack space (h = height).

Question 4
Q.414 Marks
Insert the following list of elements into the AVL tree: 12, 30, 36, 18, 25, 9, 4, 2, 17, 14, 20 and 47. Delete the elements 18, 2, 30 from the tree.
Answer
An AVL tree is a height-balanced BST: for every node, balance factor BF = h(left) − h(right) ∈ {−1, 0, +1}. After each insertion/deletion the nearest ancestor with |BF| = 2 is fixed by an LL, RR, LR or RL rotation.

The orange ring marks the key just inserted; the note under each tree gives the imbalance found and the rotation used.

12Insert 12
Tree remains balanced — no rotation.
1230Insert 30
Tree remains balanced — no rotation.
123036Insert 36
Node 12 has BF = -2 (right-right heavy) → RR case: single left rotation at 12.
12183036Insert 18
Tree remains balanced — no rotation.
1218253036Insert 25
Node 12 has BF = -2 (right-right heavy) → RR case: single left rotation at 12.
91218253036Insert 9
Node 30 has BF = +2 (left-left heavy) → LL case: single right rotation at 30.
491218253036Insert 4
Node 12 has BF = +2 (left-left heavy) → LL case: single right rotation at 12.
2491218253036Insert 2
Tree remains balanced — no rotation.
249121718253036Insert 17
Tree remains balanced — no rotation.
24912141718253036Insert 14
Node 12 has BF = -2, its right child 17 is left-heavy → RL case: right rotation at 17, then left rotation at 12.
2491214171820253036Insert 20
Tree remains balanced — no rotation.
249121417182025303647Insert 47
Tree remains balanced — no rotation.

Deletions

2491214172025303647After deleting 18
18 has two children — replace it by inorder successor 20, then delete 20 from the right subtree. All balance factors stay in {−1, 0, +1} — no rotation needed.
491214172025303647After deleting 2
2 is a leaf — remove it. All balance factors stay in {−1, 0, +1} — no rotation needed.
4912141720253647After deleting 30
30 has two children — replace it by inorder successor 36, then delete 36 from the right subtree. All balance factors stay in {−1, 0, +1} — no rotation needed.
4912141720253647
Final AVL tree after deleting 18, 2 and 30
Final AVL tree — preorder: 20, 9, 4, 14, 12, 17, 36, 25, 47; inorder: 4, 9, 12, 14, 17, 20, 25, 36, 47. Rotations during insertion: RR at 12 (on 36), RR at 12 (on 25), LL at 30 (on 9), LL at 12 (on 4), RL at 12 (on 14). Deletions used the inorder successor and needed no rotation.
Question 5
Q.5 (a)7 Marks
What is heap data structure? Explain its operations with a suitable example.
Answer
A heap is a complete binary tree that satisfies the heap property: in a max-heap every parent ≥ its children (largest key at the root); in a min-heap every parent ≤ its children. Because it is complete, it is stored in an array: for index i, left child = 2i + 1, right child = 2i + 2, parent = ⌊(i − 1)/2⌋.

Operations

  • Insert (heapify-up / percolate up): place the new key at the next free position (end of array) and swap it with its parent while it is larger than the parent. O(log n).
  • Delete (delete-max): remove the root, move the last element to the root and swap it with the larger child while it is smaller (heapify-down). O(log n).
  • Build-heap: heapify-down every internal node from ⌊n/2⌋ − 1 down to 0. O(n).
  • Peek (find-max): return the root. O(1).

Example — insert 10, 20, 15, 30, 40 into an empty max-heap

10Insert 10: [10]
1020Insert 20: [20, 10]
102015Insert 15: [20, 10, 15]
10203015Insert 30: [30, 20, 15, 10]
1030204015Insert 40: [40, 30, 15, 10, 20]

Insert 30: placed as child of 10 → 30 > 10 swap → 30 > 20 swap → becomes root. Insert 40: child of 20 → swap with 20 → swap with 30 → root.

Delete-max

10203015After deleting 40: [30, 20, 15, 10]
Root 40 removed, last element 20 moved to root, then swapped with larger child 30
Applications: priority queues, heap sort (O(n log n)), Dijkstra's and Prim's algorithms, finding k largest elements.
Q.5 (b)7 Marks
Sort the following list of elements by using merge sort: 30, 56, 78, 99, 12, 43, 10, 24, 85.
Answer

Merge sort is a divide-and-conquer algorithm: (1) divide the array into two halves, (2) conquer — sort each half recursively, (3) combine — merge the two sorted halves into one sorted array.

void mergeSort(int a[], int low, int high) {
    if (low < high) {
        int mid = (low + high) / 2;
        mergeSort(a, low, mid);
        mergeSort(a, mid + 1, high);
        merge(a, low, mid, high);   /* merge a[low..mid] and a[mid+1..high] */
    }
}

Divide phase

LevelSub-arrays
0305678991243102485
13056789912   43102485
2305678   9912   4310   2485
33056   78   99   12   43   10   24   85
430   56   78   99   12   43   10   24   85

Merge (conquer) phase

StepLeftRightMerged
130563056
2305678305678
399121299
430567812991230567899
543101043
624852485
71043248510244385
8123056789910244385101224304356788599
Sorted list: 10, 12, 24, 30, 43, 56, 78, 85, 99. Time O(n log n) in all cases (T(n) = 2T(n/2) + n); extra space O(n); stable.
Question 6
Q.6 (a)7 Marks
Compare and contrast BFS and DFS.
Answer

Both BFS and DFS are graph traversal techniques that visit every vertex reachable from a start vertex exactly once; they differ in the order of visiting.

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): BFS from A = A B C D E F (level-wise); DFS from A = A B D E C F (depth-wise).

Q.6 (b)7 Marks
Discuss Kruskal's algorithm with the following graph (vertices 0–4).
Answer

Kruskal's algorithm

  1. Sort all edges in non-decreasing order of weight.
  2. Start with a forest in which every vertex is a separate tree (T = ∅).
  3. Take the next smallest edge (u, v): if u and v are in different trees (no cycle is formed), add it to T and merge the two trees (union–find); otherwise reject it.
  4. Repeat until T has V − 1 edges.

Time: O(E log E) for sorting + nearly O(E) for union–find.

Edges sorted by weight: 1–2(3), 0–4(4), 2–4(5), 1–4(6), 3–4(7), 0–1(8), 2–3(9).

StepEdgeWeightAction
11–23Accept ✔
20–44Accept ✔
32–45Accept ✔
41–46Reject ✘ (forms cycle)
53–47Accept ✔
012344865739
Red edges: MST by Kruskal's algorithm
MST edges: 1–2 (3), 0–4 (4), 2–4 (5), 3–4 (7). Total cost = 19 (V − 1 = 4 edges).
Question 7
Q.7 (a)7 Marks
Explain shell sort algorithm and simulate it for the following data: 35, 33, 42, 10, 14, 19, 27, 44.
Answer

Shell sort (Donald Shell, 1959) is a generalisation of insertion sort. Elements that are gap positions apart are compared and sorted (gap-insertion sort); the gap is reduced (n/2, n/4, …, 1). Large early moves remove far-away disorder, so the final insertion sort (gap 1) has very little work left.

void shellSort(int a[], int n) {
    for (int gap = n / 2; gap > 0; gap /= 2)
        for (int i = gap; i < n; i++) {
            int temp = a[i], j;
            for (j = i; j >= gap && a[j - gap] > temp; j -= gap)
                a[j] = a[j - gap];
            a[j] = temp;
        }
}

n = 8, so gaps are 4, 2, 1. Each sub-list (elements gap apart) is sorted:

PassSub-lists after sortingArray after the pass
Initial—3533421014192744
gap = 4(14, 35); (19, 33); (27, 42); (10, 44)1419271035334244
gap = 2(14, 27, 35, 42); (10, 19, 33, 44)1410271935334244
gap = 1(10, 14, 19, 27, 33, 35, 42, 44)1014192733354244

gap 4: pairs (35,14), (33,19), (42,27), (10,44) are compared → 14, 19, 27 move left. gap 2: [14, 27, 35, 42] and [19, 10, 33, 44] → [10, 19, 33, 44]. gap 1: ordinary insertion sort on a nearly sorted array.

Sorted: 10, 14, 19, 27, 33, 35, 42, 44. Time ≈ O(n1.5) with this gap sequence (worst O(n²)), in-place, not stable.
Q.7 (b)7 Marks
Explain sequential search and simulate it for the following data: 4, 21, 36, 14, 62, 91, 8, 22, 81, 77, 10.
Answer

Sequential (linear) search compares the key with each element one by one from the first position until a match is found or the list ends. It works on unsorted data.

int linearSearch(int a[], int n, int key) {
    for (int i = 0; i < n; i++)
        if (a[i] == key)
            return i;          /* found at index i */
    return -1;                 /* not found */
}

Array: 42136146291822817710 (indices 0–10). No key is specified, so we search for 22 (present) and 50 (absent).

Search key = 22

Index ia[i]Comparison
0422 = 4 ? No
12122 = 21 ? No
23622 = 36 ? No
31422 = 14 ? No
46222 = 62 ? No
59122 = 91 ? No
6822 = 8 ? No
72222 = 22 ? Yes — found
22 found at index 7 (8th position) after 8 comparisons.

Search key = 50

50 is compared with all 11 elements (4, 21, 36, 14, 62, 91, 8, 22, 81, 77, 10) — no match → return −1 after 11 comparisons.

CaseComparisonsComplexity
Best (key at first position)1O(1)
Average(n + 1)/2O(n)
Worst (last / absent)nO(n)
Question 8
Q.814 Marks
Write short notes on any two of the following: (i) Stack using linked list (ii) Indexing (iii) B tree (iv) Priority queue
Answer
Any two are required (7 marks each); all four are given.

(i) Stack using linked 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.

(ii) Indexing

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.

(iii) B tree

A B-tree of order m is a balanced m-way search tree used for disk-based storage (databases, file systems) in which:
1. every node has at most m children and m − 1 keys (kept in sorted order);
2. every node except the root has at least ⌈m/2⌉ children (⌈m/2⌉ − 1 keys);
3. the root has at least 2 children if it is not a leaf;
4. all leaves are at the same level;
5. keys in a node separate the keys of its subtrees (like a BST).
3060102040507080
A B-tree of order 3 (2–3 tree)
  • Insertion: insert into the proper leaf; if it overflows (m keys), split it — the median key moves up to the parent (splits may propagate to the root, increasing height).
  • Deletion: remove the key; if a node underflows, borrow from a sibling or merge with it.
  • Advantages: height is O(logm n) — very few disk accesses because each node holds many keys (one node = one disk block).

(iv) Priority queue

A priority queue is a queue in which every element has a priority; the element with the highest priority is removed first. Elements of equal priority are served in FIFO order.
  • Types: ascending (min) priority queue — smallest key removed first; descending (max) priority queue — largest key removed first.
  • Implementations: unsorted array/list (insert O(1), delete O(n)); sorted list (insert O(n), delete O(1)); binary heap (both O(log n)) — the usual choice.
  • Applications: CPU process scheduling, Dijkstra's shortest path, Prim's MST, Huffman coding, event-driven simulation.

Example: jobs (P2, 5), (P1, 9), (P3, 2) inserted in a max priority queue are served P1, P2, P3.

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.

22 + 16 =

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