DSA - Data Structure & Algorithms, Past Papers, UOS Main Campus

Data Structures and Algorithms MIT 3rd Final Past Paper 2014 – UOS Main Campus

ProgramMIT
Semester3rd
ExamFinal Term
Year2014
AnswersSolved ✓

University of Sargodha main campus (Department of CS & IT) Data Structures and Algorithms final term paper for MIT 3rd (SS1-SS2), 16 June 2014. Retyped from the original paper, with solved answers below.

Solved answers

Q1

a) Circular queue, size 5, one slot sacrificed (capacity 4). front = index of first element, rear = next free index; empty when front = rear, full when (rear + 1) % 5 = front.

Operation[0][1][2][3][4]frontrear
start00
add(A)A01
add(B)AB02
add(C)ABC03
remove → ABC13
add(D)BCD14
add(E)BCDE10 (full)
remove → BCDE20
add(F)FCDE21 (full)
add(G)FCDE21 — overflow, G not added

b) Output: obj = que.first() = “a” (first is not removed). The queue becomes a, b, c, ad, axa, so the program prints a_b_c_ad_axa_

Q2 – Doubly linked list with nodes 1 to 4

struct DNode { int data; DNode *prev, *next; };
DNode *head = NULL, *tail = NULL;
for (int i = 1; i <= 4; i++) {
    DNode *n = new DNode;
    n->data = i; n->next = NULL; n->prev = tail;
    if (tail == NULL) head = n; else tail->next = n;
    tail = n;
}
// NULL <- 1 <-> 2 <-> 3 <-> 4 -> NULL

Q3 – Traversals

  • Preorder: A B C D E F G H I J K L M N
  • Post-order: D C G F H E B K J M N L I A

Q4 – Kruskal’s algorithm

Edges in increasing order: c–f 1, c–d 2, f–g 2, a–b 4, e–f 5, e–g 6, d–e 7, a–c 8, b–d 8, b–c 9, d–f 9, b–e 10.

EdgeWeightAction
c–f1accept
c–d2accept
f–g2accept
a–b4accept
e–f5accept
e–g6reject (cycle e–f–g)
d–e7reject (cycle)
a–c8accept — joins {a, b} with the rest

MST T = {c–f, c–d, f–g, a–b, e–f, a–c}, total weight = 1 + 2 + 2 + 4 + 5 + 8 = 22 (6 edges for 7 vertices). Choosing b–d (also 8) instead of a–c gives an equally minimal tree.

Q5 – Dijkstra from s

Edges: s→c 3, s→d 9, s→e 2, c→s 2, c→b 4, c→d 1, b→c 7, b→s 7, d→e 5, e→d 2.

IterationVertex addedSd(s,b,c,d,e)π(b,c,d,e)
init—{}0, ∞, ∞, ∞, ∞–, –, –, –
1s{s}0, ∞, 3, 9, 2–, s, s, s
2e{s, e}0, ∞, 3, 4, 2–, s, e, s
3c{s, e, c}0, 7, 3, 4, 2c, s, e, s
4d{s, e, c, d}0, 7, 3, 4, 2c, s, e, s
5b{s, e, c, d, b}0, 7, 3, 4, 2c, s, e, s

Shortest distances: s 0, e 2, c 3, d 4 (s→e→d), b 7 (s→c→b).

Save this paper for offline studyDownload the question paper, or save the paper together with all solved answers as a PDF.
↓ Download Paper (JPG)

About Saif R

An educator and technology enthusiast passionate about empowering students through quality education and digital learning. Dedicated to making academic resources and opportunities accessible to everyone.