Computer Science - 1 Fundamentals of Algorithms - 5 Sorting Algorithms

BUBBLE SORT:

  • Bubble sort involves making passes through a list and swapping elements in the wrong order

  • Each pass puts another item in order, going from right to left

  • This is done by going through a list and sequentially looking at each pair, swapping them if they are out of order

  • Going through the list once constitutes one pass

  • Here is what a ‘first pass’ might look like

Bubble Sort: Python:

Bubble Sort: Pseudocode:

MERGE SORT:

  • Merge sort involves splitting the list into groups of one and then slowly merging the groups (as well as sorting) until the list is together again

  • You divide a list of length n into n sublists of 1

  • You then go through, comparing 2 lists together. With lists of more than one, you reorder within sublists. This is done by comparing the current first value in each list and then adding the lesser to the new list.