DAA Review Qns
DAA Review Qns
DAA Review Qns
i) Space complexity
ii) Time complexity (4 marks)
b) Using a pseudo code, describe the bubble sort algorithm. (6 marks)
c) If G is an undirected graph, define the following concepts associated with the graph
i) Degree
ii) Neighbor (4 marks)
d) Briefly describe how the binary search algorithm works (4 marks)
e) Before a binary search operates on an array input of size n, what needs to be done?
(2 marks)
f) Differentiate between topological sorting and topological order as used in graph applications.
(6 marks)
g) Explain how the following graph traversal strategies work.
i. Depth First Search (DFS)
ii. Breath First Search (BFS) (4 marks)
h) Briefly describe the following graph applications
iii. Euler circuit
iv. Hamilton circuit
v. Travelling sales person problem (8 marks)
b) Define the term “recurrence relation”. (2 marks)
c) Give an explicit formula for the Fibonacci numbers (6 marks)
d) Explain a necessary and sufficient condition for a graph to have a spanning tree
(2 marks)
e) Compare dynamic programming and divide and conquer problem solving strategies.
(2 marks)
f) Describe any two computer graphs representations techniques (6 marks)
Page 1 of 5
g) Given the above graph, generate a minimum spanning tree using the Kruskal’s algorithm
(5
marks)
h) Differentiate between internal sort and external sort algorithms (4 marks)
i) Someone deposits $10,000 in a savings account at a bank yielding 5% per year with interest
compounded annually. How much money will be in the account after 30 years? (5 marks)
j) With an aid of a diagram, describe the Prim’s minimum spanning tree algorithm
(8 marks)
k) What is the maximum number of comparison required by a merge sort algorithm to sort an array
of size 6? (2 marks)
l) Show that the complexity of merge sort algorithm is O(N log2 N) (4 marks)
m) Given the following graph, sketch a Depth First Search tree. (6 marks)
Page 2 of 5
for j=1 to N
{
If i<=j then
sum++
}
}
return sum
}
c) Describe the Kruskal’s algorithm for solving the minimum spanning tree
problem
[4 marks]
Page 3 of 5
i. Consistency
ii. Completeness
iii. Decidability
d) Discuss the similarity between dynamic programming and divide and conquer algorithm
design paradigms [2 marks]
e) Illustrate, step by step how bubble sort would sort the following input data
5 1 3 6 4 [4 marks]
d) You have the following coin denominations: 25c, 10c, 5c and 1c. A
customer requires a change of 63c. By listing the coins returned as change,
describe how you would apply the greedy strategy to make the change in the
most optimal manner [4 marks]
Page 4 of 5
fib(n)
If n = = 0 or 1
Return 1
Else
Return fib(n-1) + fib(n-2);
b) Write an algorithm (in pseudocode) to compute the product of all the odd integers in a
non-empty array. [6 marks]
c) Explain 2 motivations for proving the correctness of algorithms [2 marks]
Page 5 of 5