Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

21.2 Algo

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

NATIONAL SCHOOL OF BUSINESS MANAGEMENT

BSc in Management Information Systems (Special) (NSBM)– 21.2


BSc (Honours) in Software Engineering (NSBM)– 21.2
BSc (Honours) in Computer Networks (NSBM)– 21.2
BSc (Honours) in Computer Science (NSBM)– 21.2
BSc (Honours) Software Engineering (PU)– 21.2
BSc (Honours) Computer Networks (PU)– 21.2
BSc (Honours) Computer Science (PU)– 21.2
BSc (Honours) Computer Security (PU)– 21.2

Year 01 Semester 02 Examination


16th August 2022
CS106.3 - Algorithms and Data Structures

Instructions to Candidates

1. Answer all questions.


2. The time allocated for the examination is five (05) hours (Including downloading and
uploading time). Please type your answer unless a diagram is required. Diagrams can be
handwritten and attached as a figure.
3. Weightage of Examination: 60% out of final grade
4. Download the paper and provide answers to the questions in a word document.
5. Please upload the document with answers (Answer Script) to the submission link before
the submission link expires. Answer script should be uploaded in PDF Format
6. Under any circumstances, E-mail submissions would not be taken into consideration for
marking. The incomplete attempt would be counted as a MISSED ATTEMPT.
7. The Naming convention of the answer script – Module Code_Subject Name_Index No
(E.g. CS106_DSA_100065)
8. You must adhere to the online examination guidelines when submitting the answer script
to N-Learn.
9. Your answers will be subjected to Turnitin similarity check, hence, direct copying and
pasting from internet sources, friend’s answers etc. will be penalized.

Page 1 of 4
Question 01: This question will evaluate your knowledge of basic data structures like array, stack,
queue, and linked list. (Total Mark= 30)

I. Graphically illustrate the insert (push) and remove (pop) functions. You may insert each character
of your first name into the stack for the illustrations and remove the 2nd character from the stack.
Note: You’re required to mark how the ‘top’ position changes during the execution. (5 Marks)

II. Graphically illustrate the insert (enqueue) and remove (dequeue) functions. You may insert each
character of your first name into the queue for the illustrations and remove the 2 nd character
from the queue. Note: You’re required to mark how the ‘front’ and ‘rear’ positions change during
the execution. (5 Marks)

III. Write down a code snippet for push() function and enqueue() function. Put careful attention to
the order of steps. (4 Marks)

IV. Derive the DFS and BFS output of the following graph. Identify the suitable data structures used
in these two scenarios. Assume it starts from “S” and follows ascending order. (6 Marks)

V. Consider the following postfix notation. Select a suitable data structure to retrieve the
outcome. (4 Marks)
10 20 ∗ 30 15 + −
VI. Nodes for a doubly linked list are defined to have the following structure:
data The next instance variable stores a reference to the next
node in the list, and the prev instance variable refers to the
next previous node in the list. Below is a list of three of these
nodes, along with two reference variables, p and q, that
prev
refer to specific nodes in the list.
Derive three expressions refer to the third node in the list referring
to the figure below.
(6 Marks)

n p

Page 2 of 4
Question 02: This question will evaluate your understanding of searching and sorting algorithms.
(Total Mark= 25)

I. Apply main searching algorithms and diagrammatically represent how these algorithms will
perform on the following elements if the search key is 8. (8 Marks)

32 53 21 8 85 3 71

II. Graphically illustrate the steps involved in the bubble sort and selection sort algorithm if you
have applied them to sort the above dataset. (6 Marks)

III. Now take your birthdate (e.g. 2018-10-02 as 2,0,1,8,1,0,0,2 so it will look like as below array)
as the input. Graphically illustrate how to apply the merge sort algorithm to sort the integer
set. Note: We need to make the integers set in descending order. (5 Marks)
Note: If you have born on 2018-10-02, your input array will look like this:
2 0 1 8 1 0 0 2

IV. Where to best apply the insertion sort? Discuss the worst-case scenario of this algorithm.
(2 Marks)

V. Discuss the “best” and “worst” case scenarios when finding an item of an array with 1024 data
elements using linear search and binary search algorithms. (4 marks)

Question 03: This question is based on recursion and algorithmic complexity. (Total Mark= 20)

I. Consider the following code snippet.


long fib( int n){
if (n<2)
return n;
return fib(n-1) + fib(n-2);
}

a. Identify the base case (base) and the recursive call. (2 marks)

b. How many recursive calls will generate if you call for fib(5)? (2 Marks)

c. What is the final output? (3 Marks)

II. Derive the output of the following recursive functions. If n=10. (4 Marks)

Page 3 of 4
void myFunction(int n) void myFunction(int n)

{ {

if(n == 0) if(n == 0)
return; return;
myFunction (n-1); printf("%d ",n);
printf("%d ",n); myFunction (n-1);
}
}

III. Calculate the complexity of the following two algorithms. (4 Marks)

IV. Assume that each of the expressions has the processing time T(n) for solving a problem of size
n. Specify the Big-Oh complexity of each algorithm. (5 Marks)
a. 5 + 0.001n3 + 0.025n
b. 500n + 100n1.5 + 50n log10 n
c. 0.3n + 5n1.5 + 2.5n1.75
d. n2log2 n + n(log2 n) 2
e. n log3 n + n log2 n

Question 04: This question checks your knowledge and understanding of the trees and related
concepts. (Total Mark= 25)

a. Insert the values 14, 13, 2, 5, 6, 7, 8, 17, 16 and 25 in that order into a binary search tree.
(5 Marks)
b. For the above-developed graph derive the below traversal methods. (6 Marks)
In order, Pre-order and Post order output.
c. Calculate the total value of leaf nodes. (2 Marks)
d. Derive the path to node 15. (1 Mark)
e. What is the depth of node 15? (1 Mark)
f. What is the height of the resultant tree? (2 Marks)
g. Consider the below node counts of three tree structures. Which one could make a
perfect binary tree? What is the height of that tree? (4 Marks)
16 63 127
h. Derive the equivalent expression trees for the below expressions. (4 Marks)

a + (b * c) + d * (e + f)

(5-x)*y+6/(x + z)
Page 4 of 4

You might also like