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

Data Structures and Algorithms BSSE 3rd Final Past Paper 2016 – UOS Main Campus

ProgramBSSE
Semester3rd
ExamFinal Term
Year2016
AnswersSolved ✓

University of Sargodha main campus (Department of Computer Science) BSSE 3rd semester Data Structures and Algorithms (CMP-310) final term paper, 20 January 2016. Retyped from the original paper, with solved answers below.

Paper set byDr. Bushra JamilView official UOS faculty profile →

The available copy of this paper starts from Question 2 (Question 1 was not included).

Solved answers

Q2

a) (A + B/C) * (D $ (E − F) + G) − H ($ = exponent, highest precedence)

  • Prefix: − * + A / B C + $ D − E F G H
  • Postfix: A B C / + D E F − $ G + * H −

c) Tree traversals (root −, left subtree A * B, right subtree (C + D) * (P / Q)):

  • Pre-order: − * A B * + C D / P Q
  • In-order: A * B − C + D * P / Q
  • Post-order: A B * C D + P Q / * −

Q3

a) Insertion sort dry run on 20, 35, 40, 3, 10, 15, 2:

PassElement insertedList after pass
13520, 35, 40, 3, 10, 15, 2
24020, 35, 40, 3, 10, 15, 2
333, 20, 35, 40, 10, 15, 2
4103, 10, 20, 35, 40, 15, 2
5153, 10, 15, 20, 35, 40, 2
622, 3, 10, 15, 20, 35, 40

b) Quick sort with partition:

int partition(int a[], int low, int high) {
    int pivot = a[high];          // last element as pivot
    int i = low - 1;
    for (int j = low; j < high; j++)
        if (a[j] <= pivot) { i++; swap(a[i], a[j]); }
    swap(a[i + 1], a[high]);
    return i + 1;                 // final position of pivot
}

void quickSort(int a[], int low, int high) {
    if (low < high) {
        int p = partition(a, low, high);
        quickSort(a, low, p - 1);
        quickSort(a, p + 1, high);
    }
}

Q4

a) Delete a value from a circular array:

// circular array (queue) of size N; front points to first element
int deleteValue() {
    if (count == 0) { cout << "Underflow"; return -1; }
    int v = a[front];
    front = (front + 1) % N;
    count--;
    return v;
}

b) Merge routine of merge sort:

void merge(int a[], int low, int mid, int high) {
    int temp[100], i = low, j = mid + 1, k = 0;
    while (i <= mid && j <= high)
        temp[k++] = (a[i] <= a[j]) ? a[i++] : a[j++];
    while (i <= mid)  temp[k++] = a[i++];
    while (j <= high) temp[k++] = a[j++];
    for (i = low, k = 0; i <= high; i++, k++) a[i] = temp[k];
}

c) BST for 35, 23, 46, 12, 52, 4, 56, 18, 10, 14:

35
           /      \
         23        46
        /            \
      12              52
     /  \               \
    4    18              56
     \   /
     10 14

In-order traversal of this BST gives the sorted list 4, 10, 12, 14, 18, 23, 35, 46, 52, 56.

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.