bubble sort algorithm
compares adjacent data items and orders them
several passes may be needed to sort the whole list
order of sorting
data can be sorted into ascending or descending order
how a bubble sort works
A student has stored the names of some friends in a list
David, Claire, Stefan, Sophie, Matt
Show the stages of a bubble sort when applied to this data to sort it into ascending order [5]
pass 1: *Claire, *David, Stefan, Sophie, Matt Claire, David, Stefan, Sophie, Matt Claire, David, *Sophie, *Stefan, Matt Claire, David, Sophie, *Matt, *Stefan
pass 2:
Claire, David, *Matt, *Sophie, Stefan
pass 3:
Claire, David, Matt, Sophie, Stefan
Show the stages of a bubble sort when applied to the following data to sort it into ascending order:
4, 1, 2, 6, 3, 5 [5]
pass 1: *1 *4 2 6 3 5 1 *2 *4 6 3 5 1 2 4 6 3 5 1 2 4 *3 *6 5 1 2 4 3 *5 *6
pass 2:
1 2 4 3 5 6
1 2 4 3 5 6
1 2 *3 *4 5 6