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

210CT/6

August 2021 Session


INTI International College Penang
School of Engineering and Technology

210CT Date: 7 December 2021

Programming, Algorithms Time: 8.00am – 10.30am


and Data Structures

Instructions to candidates
Time allowed : 02 hours 30 minutes
(Note : Including scanning and uploading the answers to Blackboard)

This is an Open Book Examination

Answer: ALL QUESTIONS

The total number of questions in this paper: 3

Marks vary depending on the questions

Start each question on a new page and carefully identify your answers with the
correct question number

Page 1 of 8
210CT/6

Answer ALL the questions Marks vary depending on the questions


1 Follow below steps to obtain a list of 4 numbers based on your INTI student ID:
(Note : INTI student ID consists of 8 digits after the letter “P”.)

• num1 : 1st – 3rd digit


• num2 : 4th – 6th digit
• num3 : 7th – 8th digit
• num4: last and first digit

For example, if your INTI student Id is P12345678, then the four numbers are 123, 456,
78, 81.

IMPORTANT : You must use your 4 generated numbers to answer Question 1(a)-
(d) as instructed in each question. No marks will be awarded if you use other
numbers for your solutions.

(a) (i) Replace num1-num4 with the four generated numbers (based on your student
ID as stated earlier) and construct a AVL tree for the following list in order :

num1, num2, num3, num4, 167, 111, 50,21

Show the working steps. For steps that required rotation show the tree before
and after rotation.
Note: Assume same number will always insert in the right hand of the tree.

(8 marks)

(ii) List the post-order traversal of the AVL tree constructed in Question 1 a(i).

(4 marks)

Continue

Page 2 of 8
210CT/6

(b) A file contains 6 letters A,B,C,D,E,F and the frequency for each letter as below :

character Frequency
A 59
B 143
C num1
D num2
E num3
F num4

Replace num1- num4 with the 4 numbers you had generated previously based on
your INTI student id.

(i) What is the minimum bit-length to encode the file content if fit-length
encoding method to be used?
(1 mark)

(ii) Construct a huffman tree and derive the optimal codes for each letter.
(11 marks)

(iii) Calculate the saving percentage if optimal codes are used instead of fit-
length code.
(3 marks)

continue

Page 3 of 8
210CT/6

(c) The train fare to travel between state within a country is presented in an adjacent
list as below :

Node Adjacency list


A -> B(num1)
B -> C(num2) - D(num3)
C -> E(num4) - D(68) - F (123)
D -> E(46) - F(36)
E -> A(10)
F -> E(58)

(i) Construct a graph based on the above adjacent list. Replace num1-num4
with the number you had produced based on your INTI student ID.
(6 marks)

(ii) Use Dijkstra’s algorithm to find the lowest bus fare to travel to each location
starting from location A. Show your final graph (with the lowest bus fare to
each destination) as the answer.

(10 marks)

(iii) Assume the graph in Question 1(c)(i) is undirected graph. Find the
minimum spanning Tree using Kruskal’s Algorithm. Calculate the
minimum cost.

( 4 marks)

Continue

Page 4 of 8
210CT/6

2 (a) Given the following sequence of events :

Insert(20) ,
Insert(10),
Insert(40),
Remove(),
Insert(30),
Insert(45)
Insert(50),
Remove(),
Remove(),

Show the final result (in diagram with proper label ) after performing above
sequence of events in :
(i) an empty stack.
(3 marks)
(ii) an empty queue
(3 marks)

(b) Given two queue objects, XQueue and YQueue. Write a program code segment
to calculate the sum of all the odd number in XQueue and sum of all the even
numbers in YQueue respectively. Then, push both values into an empty Stack.

You are required to use the stack and queue data structures functions such as
push, pop, peek, isEmpty, enqueue, dequeue where appropriate. No any others
form of the data structure is allowed except 2 queue objects and 1 stack.

You can write the program in your choice of C++ or Python.

(6 marks)

continue

Page 5 of 8
210CT/6

(c) Given the List and Node classes declaration as follow:

C++ Python
class Node { class Node(object):
public: def __init__(self,value, stdID,marks):
string stdID self.stdID = stdID
float marks; self.marks = marks
Node* next; self.next = None
};
class List(object):
class List { def __init__(self):
public: self.head = None
Node* head; self.tail = None
Node* tail;
:
}

Assume that a list has been derived to store all the students’ marks for 210CT
subject.

Write a function (in your choice of C++ or Python) called calcPassingRate in


the list class that will calculate and return the passing rate for 210CT. Assume
the passing marks is at least 40 and above.
(7 marks)

continue

Page 6 of 8
210CT/6

3 (a) Based on the initial unsorted list: 214, 12, 46, 57, 31, 8, show the working steps
by using the following algorithm :
(i) Selection Sort
(5 marks)
(ii) Quick Sort.
Assume pivot value is always the first number in the list

( 5 marks)

(b) Express the order of growth of the following expressions using big-O notation.

(i) 200n + 7n!


(ii) 4n2+5(2n)
(iii) 600 + log 72
(iv) n3(20n2+20n+50)
(v) 100+n+ log (100n5)
(5 marks)

(c) Identify the worst case big-O running time for each of the following in terms of
n. Provide explanation to support your answer.

(i) Pop all the number from the stack and insert into another array-based
stack.

(ii) Move all N elements from a binary min heap into a sorted list (an array in
descending order)

(iii) Finding a value in a separate chaining hash table where each bucket
points to a AVL tree.

(9 marks)

continue

Page 7 of 8
210CT/6

(d) Given a binary heap in the following diagram :

(i) State the following :


 Number of leaves in the tree
 Height of the tree
 Type of binary heap and justify your answer.
(5 marks)

(ii) Illustrate in a diagram the array reprentation of the above heap.


Remember to label each of the array index in the diagram properly.
(2 marks)

(iii) Show the working steps (in the tree format) of removing the value 78
from the above heap.
(3 marks)

End

Page 8 of 8

You might also like