<aside> 👀 EXAM QUESTION: Giving an example, describe the characteristics of a recursive sorting algorithm. (4 marks)
A recursive algorithm calls itself (1 mark) using a parameter (1 mark) and has a stopping condition (1 mark).
Example: quicksort (1 mark)
</aside>
Sorting data requires putting raw data into so pre-determined order, e.g. alphabetical, ascending or descending.
The type of Sorting Algorithm used depends on the following:
<aside> 💡 - Easy to program
</aside>
1.Start with the first pair of numbers I the list and compare N(0) with N(1)
2.If N(0) > N(1) then swap, i.e. N(0) becomes N(1) and N(1) becomes N(0). If a swap took place set a flag
Go on to the next pair of numbers and repeat stage 1 and 2 until the last pair of numbers have been compared.
Note if a swap has taken place then reset the flag and repeat the process. if no swap took place then end.
Start Procedure SortMyArray
n Is Integer
temp Is Integer
swapped Is Boolean
set n = length(myArray) {returns the length of myArray}
repeat
set swapped = FALSE
for i = 0 to (n – 1)
if myArray(i) < myArray(i + 1) then
temp = myArray(i + 1)
myArray(i + 1) = myArray(i)
myArray(i) = temp
swapped = TRUE
end if
end for
until (swapped = FALSE)
