April 1999
AP207: ADVANCED PROGRAMMING TECHNIQUES

QUESTION 5

Total Marks: 20 Marks

Click here to access other questions

Click to access
SAMPLE STUDENT'S SOLUTIONS
for Question 5

 

(a) (i) Describe informally the bubble sort algorithm. [2]
(ii) Describe informally the quick sort algorithm. [2]
(iii) Describe informally the selection sort algorithm.

 

[2]
(b) (i) The procedure BubbleSort takes an unsorted list x and iterates through the list, performing a bubble sort on at most one pair until the list is sorted. Show the state of the following list after each complete iteration of the BubbleSort procedure, assuming that a sorted list is one in which the value of each item increases along the list:

10,  5,  4,  1

 

[4]
(ii) The procedure SelectionSort takes an unsorted list x and iterates through the list, performing a selection sort on at most one pair until the list is sorted. Show the state of the following list after each iteration of the SelectionSort procedure, assuming that a sorted list is one in which the value of each item increases along the list:

12,  10,   6,    3,   7,   1

 

[4]
(c) Define the procedure

Procedure SelectionSort(Var List: ListType; ListSize: Integer)

used above, such that the procedure will take an unsorted list of integers and return a list which has been sorted using a selection sort into increasing order.

[6]