You are on page 1of 2

Republic of Cameroon République du Cameroun

Peace-Work-Fatherland Paix-Travail-Patrie
…………………… ……………………
The ministry of Higher education Ministère de l’enseignement supérieur
…………………… ……………………
Institut Supérieur Des Sciences, De Technologie, Institut Supérieur Des Sciences, De
Management Et Développement Durable Technologie, Management Et Développement
(ISSTMADD) Durable (ISSTMADD)

Second Semester Examination 2022/2023 Academic year


Course title: Introduction to Algorithms (SWE114) Instructor: Mr. Ndayo Fonteng
Level: 1 Time allowed: 2hrs
INSTRUCTIONS: Answer all questions following the correct numbering order and show
your working clearly. Avoid cancelation.
SECTION A: (Total = 20 marks)

1. Classify the following algorithm complexities in ascending order. O(n!), O(n2), O(kn), O(nk)
a. O(n!), O(n2), O(kn), O(nk) b. O(n!), O(nk), O(n2), O(kn)
c. O(n2), O(kn), O(nk), O(n!) d. O(n2), O(nk), O(kn), O(n!)
2. Which of the following is the correct way of declaring an array “List” of integers of size N?
a. var List[N]: integer; b. var List; c. List {20}; d. array List [N];
3. The complexity of an algorithm is measured in terms of
a. Operations and variables b. Loops and control structure
c. Time and space d. Number of lines of code
4. Which type of traversal of binary search tree outputs the value in sorted order?
a. Post order traversal b. Pre order traversal
c. in order traversal d. none
5. Big-O notation analyses the___________ scenario when computing the complexity of
algorithm
a. Average case b. Best case c. Worst case d. time
2
6. Given the execution time of an algorithm T(n) = n(n+2) + n + 4, the time complexity is given
as:
a. O(logn) b. O(n2) c. O(n) d. O(nk)
7. A graphical representation of an algorithm is known as
a. Pseudocode b. Flowchart c. Flow diagram d. Logic structure
8. a string of characters usually written in double quotes is called?
a. Variable b. Constant c. Literal d. Identifier
9. To avoid an infinite call of a recursive function we need.
a. A base clause b. A condition c. A return statement d. A for loop
10. given a list 9 5 6 1 4 2 Using bubble sort, for the first iteration we will obtain
a. 5 6 1 4 2 9 b. 2 5 6 1 4 9 c. 5 9 6 1 4 2 d. 1 2 4 5 6 9
11. What is the difference between a while loop and a repeat until loop?
a. while loop is an entry control loop, b. while loop executes only one time, repeat
repeat until loop is an exit control loop until execute it instructions several times
c. while loop has a stop condition d. There is no difference

1
SECTION B: (Total = 50 marks)

1. a. what is an algorithm? 2 marks

b. what is the main difference between a function and a procedure? 2 marks


c. Consider the following algorithm written using pseudocode.
Algorithm algoname.
Begin
Var i,j,temp,size;
Var List[size];
for i  1 to size do
for j  i+1 to size do
if (List[j] < List[i]) then
temp List[j];
List[j]  List[i];
List[i]  temp;
end_if
end_for
end_for
end.

i. In what other way can the algorithm be represented? 1 mark


ii. From the algorithm, list one variable which is of primitive data type and one which is of a
complex datatype 2 marks
iii. What does the algorithm perform? 1 mark
iv. Identify the control structures in the algorithm. 3 marks
v. Given the list [5 1 4 2 6 3] what will be the result when the algorithm is dry ran? 2 marks
vi. Calculate the Execution time of the above algorithm. Consider the algorithm basic
operations to be mathematical and assignment operations. 3 marks
vii. From the execution time, deduce the time complexity using the landau notation. 2 marks
viii. What other notations can be used to calculate the time complexity of an algorithm? 1 mark

2. Given the following elements, (9, 7, 12, 5, 6, 11, 14, 8, 13, 4, 10, 15)
i. Inserted the above elements in a binary search tree. 5 marks
ii. From your tree,
a. Cite the number of levels 1 mark
b. Identify the root node and any two leaf nodes 2 marks
c. What is the result of the preorder traversal? 3 marks
d. Identify the ancestor (parent) node of the element “10” 1 mark
iii. What are the two main traversals of a binary search tree? 2 marks
iv. What do we mean by traversing a binary search tree? 2 marks
v. State two differences between a binary tree and an array. 2 marks
vi. Define the following terms related to graphs
a. Edge 1 mark
b. Vertex 1 mark
c. Path 1 mark
3. Write an algorithm that can calculate the determinant of a 2x2 matrix. 5 marks
4. Briefly explain the divide and conquer algorithm design strategy 5 marks

You might also like