0% found this document useful (0 votes)
74 views3 pages

CCS 3102 Design and Analysis of Algorithms Exam

Uploaded by

gabrieloluoch926
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)
74 views3 pages

CCS 3102 Design and Analysis of Algorithms Exam

Uploaded by

gabrieloluoch926
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/ 3

DEDAN KIMATHI UNIVERSITY OF TECHNOLOGY

University Examinations 2020/2021

THIRD YEAR SEMESTER II EXAMINATION FOR THE DEGREE OF BACHELOR OF


SCIENCE IN COMPUTER SCIENCE

CCS 3102: DESIGN AND ANALYSIS OF ALGORITHMS

DATE: SEPTEMBER 2020 TIME: 2 HOURS


Instructions: Answer Question 1 and Any Other Two.

QUESTION ONE (30 MARKS)

a. The development of dynamic programming algorithm can be broken into a sequence of steps.
Describe the general procedure of dynamic programming. (4marks)

b. Suppose you have two algorithms which give correct solutions to some computational problem,
what criteria will you use to select one of them. (3 marks)

c. Differentiate between the following.


i) Breadth-first search and Depth-first search (2 marks)
ii) P and NP problems (2 marks)
iii. Feasible and optimal solution (2 marks)

d. Quicksort is claimed to have an expected running time of O(n log n), but it could at times be as
slow as O(n2). Discuss how you can fix Quicksort clearly explaining how your solution will
change the expected time from O(n2) to O(n log n). (4 marks)

e. Give four reasons why we study algorithms and performance. (4 marks)

f. How is the efficiency of the algorithm defined? (2 marks)

g. Outline two differences between dynamic programming and divide-and-conquer. (4 marks)

h. Assuming that a tree has the preorder and inorder representations given below, reconstruct the
tree. (3 marks)
Preorder: [25, 15, 10, 4, 12, 22, 18, 24, 50, 35, 31, 44, 70, 66, 90]
Inorder: [4, 10, 12, 15, 18, 22, 24, 25, 31, 35, 44, 50, 66, 70, 90]
QUESTION TWO (20 MARKS)
a) For the following recurrence relations, give an expression for the runtime T (n) if the recurrence
can be solved with the Master Theorem. Otherwise, indicate that the Master Theorem does not
apply and justify your answer.
i. T (n) = 7T (n/2) + n/ log n (2 marks)
ii. T (n) = 0.5T (n/2) + 1/n (2 marks)
iii. Describe two limitations of recursive solutions. (2 marks)

b) When comparing algorithms we at times have to resort to empirical analysis rather than
theoretical analysis. Give three reasons why we perform empirical analysis. (3 marks)

c) A cable company wants to connect five villages to their network which currently extends to the
market town of Avonford. Using the weighted graph below compute the minimum length of
cable needed to connect all five villages. Show all working. (6 marks)

d) Given an array of 10 elements: 4, 1, 3, 2, 16, 9, 10, 14, 8, 7 build a heap structure and perform
heap sort on the tree such that it satisfies the heap property. (5 marks)

QUESTION THREE (20 MARKS)

a) Suppose you are given the list of programs below each with a start time and a finish time to run
on a single processor machine with no preemption:

Program 1 2 3 4 5 6 7 8 9 10 11
Start 0 1 2 4 6 5 2 8 2 12 8
Finish 3 6 5 7 10 9 8 11 13 15 12

i. Schedule the programs using an appropriate algorithm. Clearly indicate the maximum
programs which can be successfully completed. (4 marks)
ii. State two real life applications of the algorithm used in (i) above. (2 marks)
iii. We use loop invariants to help us understand why an algorithm is correct. Explain three
things we must show about a loop invariant. (3 marks)
b) Describe the algorithm used to DELETE a node from a binary search tree. You do NOT have to
give all the details of the algorithm. Just describe the major steps in the algorithm. (4 marks)

c) Use the Hash table given below to answer the following questions.

i. Define a collision giving one method of resolving it. (2 marks)


ii. Insert the keys [18, 41, 22, 44, 59, 32, 31, and 73] in this order. (5 marks)

QUESTION FOUR (20 MARKS)

a) Assume that we have a knapsack with max weight capacity W = 11. Our objective is to fill the
knapsack with items such that the benefit (value or profit) is maximized. The following table
contains the items along with their value and weight.

Item i 1 2 3 4 5
Value val 1 6 18 22 28
Weight wt 1 2 5 6 7

i. Solve this problem using dynamic programming strategy. (5 marks)


ii. What is the value of the optimal solution? (1 mark)
iii. Which items will be placed in the knapsack? (1 mark)
iv. Differentiate between dynamic programming and Greedy algorithms. (3 marks)

b) Suppose we want to encode a text message with the characters below occurring with the
following frequencies:

Character a e i o u s t
Frequency 10 15 12 3 4 13 1

i. Generate an optimal Huffman tree and fill the table below. (7 marks)
Character Frequency Code Code length
a 10
e 15
i 12
o 3
u 4
s 13
t 1

ii. How many bits may be required for encoding the text message? (1 mark)
iii. What makes an algorithm greedy? (2 marks)

You might also like