CSC508 TEST2 16jan2023

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

CS/JAN2023/CSC508/TEST 2

CONFIDENTIAL CS/JAN2023/CSC508/TEST 2

UNIVERSITI TEKNOLOGI MARA


TEST 2

COURSE : DATA STRUCTURES


COURSE CODE : CSC508

DATE : 16 JANUARY 2023


TIME : 2 HOURS
SEMESTER : OCT 2022 – FEB 2023
NAME :
STUDENT’S ID :
STUDENT

INSTRUCTIONS TO CANDIDATES

1. This paper consists of FOUR (4) questions only.


2. Answer ALL questions.

Score Total Marks

QUESTION 1 14

QUESTION 2 20

QUESTION 3 20

QUESTION 4 16

TOTAL SCORE 70

Answer ALL questions


CS/JAN2023/CSC508/TEST 2

QUESTION 1 (14 marks)


From the given list of items below, illustrate the execution of each pass of the following sorting
algorithms:
93 23 87 22 65 5 90 68
a) Selection Sort (6 marks)
b) Heap Sort (8 marks)

QUESTION 2 (20 marks)


Consider the following list :
49 55 60 68 73 8 12 23 39 45 4

How many comparisons are required to find whether items 73 and 99 are in the list?
a) Using Sequential Search algorithm? (5 marks)
b) Using Binary Search algorithm? (5 marks)

c) Hashing.
Let H be a closed hash table of size 12 (indices 0 to 11) in which the following set of
keys are currently stored: {32, 765, 81, 900, 74, 70, 86, 345, 48, 79}.
Show the content of Hash Table if the following algorithm is used:
i) Linear Probing (5 marks)
ii) Chaining (5 marks)

Assume that the hash function used is h(x) = x mod 12.

QUESTION 3 (20 marks)


a) Given the following list of items, construct the Binary Search Tree.

BEL100 ENT300 ITC511 MAT499 CSC508 CTU153 QMT155


(5 marks)
CS/JAN2023/CSC508/TEST 2

b) Based on the AVL Tree below, answer the following questions:

50
0

30 80

40 55
25

48

i. Insert values 70 AND 45 into the AVL Tree above. Show the work done after
each insertion. The resulting tree must also be an AVL tree.
(8 marks)
ii. What are the balance factors at each node after the insertion in (i).
(2 marks)

c) Write a recursive method countLeaves() for class BinarySearchTree, which


will count the number of leaves in a BST.
(5 marks)

QUESTION 4 (16 marks)


a) Explain the term directed and undirected graph. Give an example for each type of
graph.
(4 marks)
b) Given the following graph G, traverse the graph using DFS traversal starting from
vertex A.
(5 marks)

E F
A
C

G
B
CS/JAN2023/CSC508/TEST 2

c) Based on the graph in (b), if all the edges have weights associated to it, find the
shortest path from vertex A to any other vertices in the graph using Djikstra algorithm.

3 E F
1 7
A
C 2 1

3 D 9
8
G
B
5

(7 marks)

END OF QUESTION PAPER

GOOD LUCK FOR YOUR FINAL EXAM

*** Ilmu itu didapati dengan lidah yang gemar bertanya


dan akal yang suka berfikir ***
(Abdullah Ibnu Abbas)

You might also like