HNDSE 21.2F Programming Data Structures and Algorithms

You might also like

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

National Institute of Business Management

School of Computing and Engineering

BSc (Hons) Computing | ITB | EHNS-Year 1


Higher National Diploma in Software Engineering–21.2F
Programming Data structures and Algorithms-1
Time Allowed: Three Hours 27th May 2022|9AM-12PM
INSTRUCTIONS TO CANDIDATES

• This paper contains 5 questions. Answer ALL questions.


• Marks for each question is indicated.
• This is a closed book examination.

Question 1 (20 Marks)


A. Select the most suitable data structure to implement the following scenarios. (4 marks)
i. Reverse the characters in your name.
ii. Issue numbered tokens for the people who arrived at a petrol shed.

B. Implement methods to take inputs for the above data structures a) and b). Use the
standard names of the methods. Assume that all the other methods are available.
(8 marks)

C. Implement methods to remove values from the above data structures. Use the standard
names of the methods. Assume that all the other methods are available. (8 marks)

Question 2 (20 Marks)


A. List two advantages of a linked list data structure over a non-linear data structure. (2 marks)
B. Illustrate and discuss doubly linked list and circular linked list with a suitable diagram. (6
marks)
C. Write an algorithm to delete the last element from a doubly linked list. (6 marks)
D. Given a linked list, rearrange it by separating odd nodes from even ones. All even nodes
should come before all odd nodes in the output list, and the relative order of even and odd
nodes should be maintained. (6 marks)

Page 1 of 4
Question 3 (27 Marks)
A. Introduce below trees very briefly.
i. Binary tree (2 Marks)
ii. AVL tree (2 Marks)
iii. Red, black tree. (2 Marks)

B. Draw a binary search tree to store following values.


Values: 100 82 102 68 28 10 50 61 (4 Marks)

C. Draw an AVL tree to store following values. (4 Marks)


Values: 30 12 15 42 52 6

D. Write following traversal techniques for the tree given below.


i. Pre-order (2 Marks)
ii. Post-order (2 Marks)
iii. In-order (2 Marks)

E. You are required to read an array and sort the numbers using one of the techniques below.
(7 Marks)
Bubble sort
Insertion sort
Merge sort

Page 2 of 4
Question 4 (23 Marks)

A. Find the shortest path from ‘S’ to each vertex in the below graph using Dijkstra’s
algorithm. (8 marks)

B.
i. Draw 3 spanning tress for below graph. (6 marks)

ii. Find the Minimum Cost Spanning Tree for the below graph using Kruskal’s
Algorithm. (9 marks)

Page 3 of 4
Question 5 (10 Marks)

A. For the function f(n) given below, give an asymptotic upper bound using “big-O" notation.

I. i F(n) = 100n2 + 9* n ANSWER: [1 mark]

II. ii for (int i = 1; i <= n; i++){ ANSWER: [1 mark]


for(int j = 1; j < n; j = j ++)
for(int w = 1; w < 8; w ++) {
System.out.println(i + "-" + j);
}
}
III. iii F(n)= .001n + 100 ANSWER: [1 mark]

IV. iv for(int j = 1; j < n; j = j * 2) { ANSWER: [1 mark]


System.out.println(i + "-" + j);
}
V. v for (int i = 1; i <= n; i++){ ANSWER: [1 mark]
for(int j = 1; j < n; j = j ++)
for(int w = 1; w < n; w ++) {
System.out.println(i + "-" + j);
}
}

B.
i. Describe the meaning of Space complexity. [2 marks]
ii. Short Description for Big - Oh (O) Asymptotic Notation. [1 mark]
iii. Short Description for Big - Omega (Ω) Asymptotic Notation. [1 mark]
iv. Short Description for Big - Theta (Θ) Asymptotic Notation. [1 mark]

Page 4 of 4

You might also like