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.
- Start at the first item in the list
- Compare the current item with the next one
- If the two items are in the wrong position, swap them.
- Move to the next item in the list.
- Repeat from step 2 until all the unsorted items have been compared.
Bubble Sort in Python:
|· 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)|
491 total views, 1 views today