Professional Documents
Culture Documents
SEMESTER I, 20152016 Midterm
SEMESTER I, 20152016 Midterm
Name : Matric No :
Section No: ___________________________
KULLIYYAH OF ENGINEERING
Duration : 2 Hour
This question paper consists of (5) printed pages (including cover page)
with Two (2) sections.
INSTRUCTION(S) TO CANDIDATES
DO NOT OPEN UNTIL YOU ARE ASKED TO DO SO
Any form of cheating or attempt to cheat is a serious offence which may lead to dismissal.
1
ECE 3231Algorithms and Programming | Mid-Term Examination | 4 April 2015
Name : Matric No :
Section No: ___________________________
A1. In algorithm analysis, when the input size increases the algorithm may take time
to compute the result, hence finding the order of growth of the algorithm is very
crucial. Given N as size of array to search for a key K, Use the most
appropriate notation among O, Ɵ, Ω, and θ, to indicate the time efficiency class
of sequential search of a key given
a. in the worst case.
b. in the best case.
c. in the average case.
(3 Marks)
A2. Why is experimental studies not consider efficient when calculating running time
of an algorithm? (2 marks)
A3. Define an algorithm, what are the 2 main components to be considered when
A4. In a recent court case, a judge cited a city for contempt and ordered a fine of $2
for the first day. Each subsequent day, until the city followed the judge’s order, the
fine was squared (i.e., the fine progressed as follows: $2, $4, $16, $256, $65,536, . .
.).
a. What would be the fine on day N?
b. How many days would it take for the fine to reach D dollars (a Big-Oh answer
will do)? (4 marks)
2
ECE 3231Algorithms and Programming | Mid-Term Examination | 4 April 2015
Name : Matric No :
Section No: ___________________________
A6. Indicate the running time of each algorithm or code segment. (10 marks)
(a)
for( i = 0; i < n; ++i )
for( j = 0; j < n; ++j )
++k;
(d)
sum = 0;
for( i = 0; i < n; ++i )
for( j = 0; j < n * n; ++j )
++sum;
2n + 10 is O(n)
A8.
Muhammad ibn Musa al-Khwarizmi the great mathematician of 9th century states in
is The Golden Principle of Al-Khwarizmi that all complex problems of science must
be and can be solved by means of five simple steps. Elaborate on these principles
(5 Marks)
3
ECE 3231Algorithms and Programming | Mid-Term Examination | 4 April 2015
Name : Matric No :
Section No: ___________________________
B1
An important property of a linked list is that it does not have a predetermined fixed
size;, we can easily insert an element at the head or tail of the list. Write a pseudo-
code in Code Fragment addFirst(e) as shown in Figure 2. to create a new node, set
its element to the new element, set its next link to refer to the current head, and then
set the list’s head to point to the new node (4 marks)
Figure 2
4
ECE 3231Algorithms and Programming | Mid-Term Examination | 4 April 2015
Name : Matric No :
Section No: ___________________________
Figure 1
(g) Evaluate the following infix to postfix expression using stack concept (5 marks)
A*B-(C-D)/E
a. Given the definition of a binary tree , Show the result of inserting {3, 1, 4, 6,
9, 2, 5, 7, } into an initially empty binary search tree. (6 marks)
b. . Show the result of deleting the root and re-draw the Tree (3 marks)
c. provide the inorder, preorder and postorder traversals of the binary search
tree of in figure 3 a (6 marks)
“(((5+2)*(2-1))/((2+9)+((7-2)-1))*8)” (4 marks)
5
ECE 3231Algorithms and Programming | Mid-Term Examination | 4 April 2015
Name : Matric No :
Section No: ___________________________
c. What is the average probes of searching for the following ID (keys); {3, 31, 28}
(5 marks)