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
Answered by Christopher F. Computing tutor

1584 Views

See similar Computing A Level tutors

Related Computing A Level answers

All answers ▸

Describe the operations of an optical disk drive used to read data from an optical disk, such as a CD or DVD.


Give two types of management of either hardware or other resources that are performed by an operating system.


What is recursion and why is it useful?


why is the Harvard architecture is sometimes used in preference to the von Neumann architecture and give examples of each system


We're here to help

contact us iconContact usWhatsapp logoMessage us on Whatsapptelephone icon+44 (0) 203 773 6020
Facebook logoInstagram logoLinkedIn logo

© MyTutorWeb Ltd 2013–2025

Terms & Conditions|Privacy Policy
Cookie Preferences