Documente Academic
Documente Profesional
Documente Cultură
Faculty of Engineering
Department of Computer Science & Engineering
Question 1
1.
2.
3.
4.
a) Write pseudo code to perform the exchange operation of the above algorithm (line 4).
The method signature would be and a call to this method will
th th
exchange the element of A with element of .
b) Considering the integer nature of the array elements, do you think it is possible to write
the exchange operation without the need of an additional variable? If so, write pseudo
code for the new implementation of the exchange method. Use the same method
declaration as in part a).
c) What is the significance of limiting the maximum of to – in the inner for loop?
d) Perform the above algorithm on . Give steps for and
only.
Question 2
© Saliya Ekanayake
WSO2 Inc.
1.
2.
3.
4.
5.
6.
7.
i) What can you say about the elements in for any iteration of the for
loop of lines 1 – 7?
ii) How can we incorporate insertion sort with merge sort to improve the efficiency
of sorting?
d) Suggest a method to merge two separately sorted integer arrays into one final array. No
need to write pseudo code, an example based explanation is sufficient. Hint: think of the
smallest element of a sorted array.
Question 3
1.
2.
3.
4.
5.
6.
7.
8.
For any iteration of the loop in lines 3 – 6 and for any index, of what can you say
about the value of with respect to , under the following conditions of ?
i)
ii)
iii)
b) What can you say about the position of the pivot element after the completion of the
partition algorithm?
© Saliya Ekanayake
WSO2 Inc.
c) Answer the following questions based on your knowledge on max heaps and heap sort
algorithm.
16 14 10 8 7 9 3 2 4 1
th
d) We can use the following algorithm to make the sub tree rooted at
node of a heap.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
© Saliya Ekanayake
WSO2 Inc.