Data is stored in the array NameList [1:10]. This data is to be sorted. a) i) Copy
Question:
Data is stored in the array NameList [1:10]. This data is to be sorted.
a) i) Copy and complete this pseudocode algorithm for an insertion sort.
ii) A special case is when NameList is already in order. The algorithm in part a) i) is applied to this special case.
Explain how many iterations are carried out for each of the loops.
b) An alternative sort algorithm is a bubble sort:
i) As in part a) ii), a special case is when NameList is already in order. The algorithm in part b) is applied to this special case.
Explain how many iterations are carried out for each of the loops.
ii) Rewrite the algorithm in part b), using pseudocode, to reduce the number of unnecessary comparisons.
Use the same variable names where appropriate.
Step by Step Answer:
Cambridge International AS & A Level Computer Science
ISBN: 9781510457591
1st Edition
Authors: David Watson, Helen Williams