Bubble Sort

Download:

Bubble Sort

Bubble Sort Code(Code Needs To Be Copied Into Python)

townlist(Text Document Needed For Python File to Work)

Note: Make sure that townlist and the python file is in the same folder for the program to work. Remove/add comments where needed in order test out variants

Bubble Sort: (GCSE & A-Level)

This orders an unordered list of items by comparing each item with the next one and swapping them if they are out of order. The algorithm is finished when no swaps are made. It effectively ‘bubbles up’ the largest (or smallest) item to the end of the list.

Simplified Explanation:  

  1. Start at the first item in the list
  2. Compare the current item with the next one
  3. If the two items are in the wrong position, swap them.
  4. Move to the next item in the list.
  5. Repeat from step 2 until all the unsorted items have been compared.

Bubble Sort in Python:

 

Advantages: Disadvantages:
·         Not the most complex algorithm ·         Slowest sort of them all
·         Efficient on small data sets ·         Extremely inefficient for large data sets

 

Big O Notation: (A-Level)

Best Case: Average Case: Worst Case: Space Complexity
·         Linear ·         Polynomial ·         Polynomial ·         Constant
·         O(n) ·         O(n2) ·         O(n2) ·         O(1)

Recursive: (A-Level)

 299 total views,  1 views today