0% found this document useful (0 votes)
45 views4 pages

Dsa Final Paper

This document is a final term examination paper for the Algorithms and Data Structures course at COMSATS University, Islamabad, dated January 4, 2021. It includes various questions related to linked lists, stack operations, sorting algorithms, binary trees, graph algorithms, and hashing techniques, with a total of 30 marks. Students are instructed to attempt all questions and submit their handwritten answers in a specified format.

Uploaded by

habibireads
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views4 pages

Dsa Final Paper

This document is a final term examination paper for the Algorithms and Data Structures course at COMSATS University, Islamabad, dated January 4, 2021. It includes various questions related to linked lists, stack operations, sorting algorithms, binary trees, graph algorithms, and hashing techniques, with a total of 30 marks. Students are instructed to attempt all questions and submit their handwritten answers in a specified format.

Uploaded by

habibireads
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

COMSATS University, Islamabad

CUI, Islamabad Campus


Department of Computer Science
Subjective Part
Class: BS(CS)/BS(SE) Date: January 04, 2021

Subject: Algorithms and Data Structures Total Marks: 30


FINAL TERM EXAMINATION - FALL 2019
Name: _________________________ Registration Number: ________________

Instructions:

• Attempt all questions using a pen or a pencil on a paper.


• Write your registration number with each question.
• Take a picture of every handwritten answer and convert these images to pdf by camscanner.
• Save that Pdf and upload your solution.
• Make sure to upload the correct file. Otherwise, you shall get zero credit.
Submission Instructions: Upload your solution on the MS Teams as assignment.

======================= QUESTION 1 ===================== (5 marks)


a). Consider the following code for Linkedlist:
struct Node{
int item;
Node* next;
};
Node* head;
Consider the linked list represented in the following diagram:

i. Draw a diagram of the above list after the following lines of code have been executed:
Node* prev = head->next;
Node* nodeToInsert = new Node;
nodeToInsert->item = 4;
nodeToInsert->next = prev->next;
prev->next = nodeToInsert;

ii. Assume that the code represented above in part (a) has executed. What is the value of
prev->item?

Page 1/3
iii. In addition to the code above, assume the following code executes. Draw a diagram of the list after this
code executes as well.
prev = prev->next;
prev = prev->next;
Node* curr = prev->next;
prev->next = curr->next;
delete curr; curr = NULL;

b). Consider the following function XYZ () that takes two circular linked lists as arguments:

Show list1 diagrammatically when


i. list1 is a and list2 is c.
ii. list1 is c and list2 is b

======================= QUESTION 2 =================== (5 marks)


Consider the following sequence of stack operations: push(9), push(4), pop(), push(6), push(3), pop(), pop(),
push(5).
(a) Assume the stack is initially empty, what is the sequence of popped values, and what is the final state of the
stack? (Identify which end is the top of the stack).
(b) Suppose you were to replace the push and pop operations with enqueue and dequeue respectively. What would
be the sequence of dequeued values, and what would be the final state of the queue? (Identify which end is the
front of the queue).
(c) Suppose you have to replace the priority queue with simple queue. What would be the sequence of dequeued
values, and what would be the final state of the queue? (Identify which end is the front of the queue).
(d) Suppose you have replaced the simple queue with circular queue and size of queue is 4. If initially the front
and rear are both at index-2 having value 0. Where will the front and rear after applying above mentioned
operations?

Page 2/3
(e) Suppose you have replaced this with Deque and you apply following operations:
pushrear(9), pushfront(4), popfront(), pushfront(6), pushrear(3), popfront(), poprear(), pushfront(5).

===================== QUESTION 3 ====================== (5 marks)


Consider the below array of 8 numbers and show each step i.e. the array after each iteration of the outer loop. If
your registration number is even then you have to apply insertion sort else you have to apply selection sort.

The array is [21, 3, 5, (your registration number) ,10, 1, 8, 2] -> if your registration number is 15 then the
array you have to sort is [21,3,5, 15,10,1,8,2].
Show the changes in values after each iteration:

21 3 5 Your 10 1 8 No. of No. of Complexity


Reg# comparisons swaps/shifts

============ QUESTION 3 (Binary Trees/Graph/MST) ==========(5+5= 10 marks)


a) Write a function inside a BST that takes an array A of type and an integer n that denotes the size of A along
with any other additional argument that is needed. At end of the function, the array should be sorted from
largest to smallest number. Also, tell me what the initial call to this function will be?
b) Imagine you are the leader of an international gang of smugglers. One of your gang member (John) has a
very expensive diamond that he wants to deliver it to you through a series of middlemen. Each middleman
will charge some amount to deliver the diamond to the next middleman. You want to get the diamond at a
minimum cost. So you decide to tell John how exactly to deliver the diamond to you as shown in the table

Since you are an underworld boss who has studied Data Structures and Algorithms, you decide to solve
how the diamond will be delivered to you by modeling the problem as a graph and then applying an
algorithm to it. Tell me the following
i. Create a graph for this problem. (1)
ii. What algorithm will apply on it? Where will you start it from? (1)

Page 3/3
iii. Redraw the graph and highlight (make bold) the solution, i.e. make the edges and vertices of the
solution. (3)

============== QUESTION 5 (Hashing) ============ (05 marks)

Given the following input (4322, 1334, 1471, 9679, 1989, 6171, 6173, 4199) and the hash function
x mod 10.
a) Show the values in each index of array by applying linear probing method.
b) Apply the changing method and draw the diagram.

========================== BEST OF LUCK ===========================

Page 4/3

You might also like