Explain a bubble sort. You may use pseudocode and/or diagrams to help demonstrate your answer.

A bubble sort works by performing a number of passes on a list of data. With each pass the list will get closer to the final order. During a pass the algorithm compares a selected item with each item in the list. They are swapped if they are out of position. If sorting a numerical list in ascending order the number 1 would 'bubble' to the top of the list.
var length = list.lengthfor var i loop from 0 to length of list -1for var j loop from 0 to length of list -1 - iif(list(j) > list(j+1)) thenvar temporary = list(j)list(j) = list(j+1)list(j+1) = temporaryend ifnext jnext i

CF

Related Computing A Level answers

All answers ▸

What is the range of denary numbers that can be represented using 8-bit two’s complement binary integers?


What is the difference between an array and a record?


Given an unlimited number of light bulbs (that break at a certain height), and a building with 100 floors, how do you determine the height that the light bulb breaks?


Write pseudocode for the binary search algorithm and state, with an explanation, it's worst case complexity in big-O notation