Photo AI

Last Updated Sep 27, 2025

Sorting Algorithms Simplified Revision Notes

Revision notes with simplified explanations to understand Sorting Algorithms quickly and effectively.

user avatar
user avatar
user avatar
user avatar
user avatar

433+ students studying

10.1.2 Sorting Algorithms

What Are Sorting Algorithms?

Sorting algorithms are methods for organizing a list of elements (e.g., numbers, strings) into a specific order, such as ascending or descending. They are fundamental in computer science and mathematics. This note explains two key algorithms: Bubble Sort and Quick Sort.

Bubble Sort

Overview

Bubble Sort repeatedly compares adjacent elements and swaps them if they are in the wrong order. This process is repeated until the list is sorted.

Algorithm Steps

  1. Start at the beginning of the list.
  2. Compare the first pair of adjacent elements.
  3. Swap them if the first element is larger than the second (for ascending order).
  4. Move to the next pair and repeat until the end of the list.
  5. Repeat steps 141–4 for n1n-1 passes (where nn is the length of the list).

Pseudocode

FOR i = 1 TO n - 1:
    FOR j = 1 TO n - i:
        IF list[j] > list[j+1]:
            SWAP list[j] and list[j+1]
infoNote

Worked Example: Bubble Sort

Sort the list [5,3,8,6,2][5, 3, 8, 6, 2] in ascending order.


Pass 1:

  • Compare 55 and 33Swap[3,5,8,6,2][3, 5, 8, 6, 2]
  • Compare 55 and 88 → No swap → [3,5,8,6,2][3, 5, 8, 6, 2]
  • Compare 88 and 66Swap[3,5,6,8,2][3, 5, 6, 8, 2]
  • Compare 88 and 22Swap[3,5,6,2,8][3, 5, 6, 2, 8]

Pass 2:

  • Compare 33 and 55 → No swap → [3,5,6,2,8][3, 5, 6, 2, 8]
  • Compare 55 and 66 → No swap → [3,5,6,2,8][3, 5, 6, 2, 8]
  • Compare 66 and 22Swap[3,5,2,6,8][3, 5, 2, 6, 8]

Pass 3:

  • Compare 33 and 55 → No swap → [3,5,2,6,8][3, 5, 2, 6, 8]
  • Compare 55 and 22 Swap[3,2,5,6,8][3, 2, 5, 6, 8]

Pass 4:

  • Compare 33 and 22Swap[2,3,5,6,8][2, 3, 5, 6, 8]

Sorted List: [2,3,5,6,8][2, 3, 5, 6, 8]

Complexity of Bubble Sort

  • Time Complexity: O(n2)O(n^2) in the worst case (e.g., a reverse-ordered list).
  • Space Complexity: O(1)O(1) as sorting is performed in place.

Quick Sort

Overview

Quick Sort is a divide-and-conquer algorithm that selects a pivot and partitions the list into two sublists:

  • Elements smaller than the pivot.
  • Elements larger than the pivot. The process is recursively repeated on the sublists.

Algorithm Steps

  1. Select a pivot (e.g., the middle element).
  2. Partition the list into two sublists:
  • Left sublist: Elements smaller than the pivot.
  • Right sublist: Elements larger than the pivot.
  1. Recursively apply Quick Sort to the left and right sublists.
  2. Combine the sublists and pivot them into a sorted list.

Pseudocode

QuickSort(list):
    IF length of list ≤ 1:
        RETURN list
    ELSE:
        pivot = middle element of list
        left = elements < pivot
        right = elements > pivot
        RETURN QuickSort(left) + [pivot] + QuickSort(right)
infoNote

Worked Example: Quick Sort

Sort the list [5,3,8,6,2][5, 3, 8, 6, 2] in ascending order


Step 1: Select Pivot

Pivot = middle element = 88


Step 2: Partition the List

  • Left: [5,3,6,2][5, 3, 6, 2] (elements < pivot).
  • Right: [] (no elements > pivot).

Step 3: Recursively Sort Sublists

Left Sublist: [5,3,6,2][5, 3, 6, 2]

  • Pivot = middle element = 6 6

  • Left: [5,3,2][5, 3, 2]

  • Right: [] Sort [5,3,2][5, 3, 2]:

  • Pivot = 33

  • Left: [2][2]

  • Right: [5][5] Combine: [2,3,5][2, 3, 5]

Combine Left Sublist: [2,3,5,6][2, 3, 5, 6]


Step 4: Combine All Sublists

Final sorted list: [2,3,5,6,8][2, 3, 5, 6, 8]

Complexity of Quick Sort

  • Best Case: O(nlogn)O(n \log n) when partitions are balanced.
  • Worst Case: O(n2)O(n^2) when partitions are unbalanced (e.g., pivot is the smallest or largest element).
  • Space Complexity: O(logn)O(\log n) for recursion.

Comparison: Bubble Sort vs. Quick Sort

AspectBubble SortQuick Sort
Time ComplexityO(n2)O(n^2)Best: O(nlogn)O(n \log n), Worst: O(n2)O(n^2)
Space ComplexityO(1)O(1) (in place)O(logn)O(\log n) (recursive calls)
Use CaseSmall or nearly sorted listsLarge, random, or unsorted lists

Note Summary

infoNote

Common Mistakes

  1. Bubble Sort: Forgetting to reduce the number of comparisons after each pass.
  2. Quick Sort: Misidentifying the pivot or incorrectly partitioning sublists.
  3. Pivot Selection: Always use the middle element as specified; other pivot choices may cause inefficiency.
  4. Stopping Conditions: Ensure recursive calls stop for sublists of length 00 or 11.
  5. Space Mismanagement: Overlooking stack depth for recursion in Quick Sort.
infoNote

Key Formulas

  1. Bubble Sort Pseudocode:
FOR i=1 TO n1,SWAP adjacent elements if list[j]>list[j+1]\text{FOR } i = 1 \text{ TO } n-1, \quad \text{SWAP adjacent elements if } list[j] > list[j+1]
  1. Quick Sort Partitioning:
list=QuickSort(left)+[pivot]+QuickSort(right)\text{list} = \text{QuickSort(left)} + [\text{pivot}] + \text{QuickSort(right)}
Books

Only available for registered users.

Sign up now to view the full note, or log in if you already have an account!

500K+ Students Use These Powerful Tools to Master Sorting Algorithms

Enhance your understanding with flashcards, quizzes, and exams—designed to help you grasp key concepts, reinforce learning, and master any topic with confidence!

30 flashcards

Flashcards on Sorting Algorithms

Revise key concepts with interactive flashcards.

Try Further Maths Decision Maths 1 Flashcards

3 quizzes

Quizzes on Sorting Algorithms

Test your knowledge with fun and engaging quizzes.

Try Further Maths Decision Maths 1 Quizzes

29 questions

Exam questions on Sorting Algorithms

Boost your confidence with real exam questions.

Try Further Maths Decision Maths 1 Questions

27 exams created

Exam Builder on Sorting Algorithms

Create custom exams across topics for better practice!

Try Further Maths Decision Maths 1 exam builder

50 papers

Past Papers on Sorting Algorithms

Practice past papers to reinforce exam experience.

Try Further Maths Decision Maths 1 Past Papers

Other Revision Notes related to Sorting Algorithms you should explore

Discover More Revision Notes Related to Sorting Algorithms to Deepen Your Understanding and Improve Your Mastery

96%

114 rated

Algorithms

General Algorithms

user avatar
user avatar
user avatar
user avatar
user avatar

405+ studying

183KViews

96%

114 rated

Algorithms

Bin Packing Algorithms

user avatar
user avatar
user avatar
user avatar
user avatar

500+ studying

198KViews
Load more notes

Join 500,000+ A-Level students using SimpleStudy...

Join Thousands of A-Level Students Using SimpleStudy to Learn Smarter, Stay Organized, and Boost Their Grades with Confidence!

97% of Students

Report Improved Results

98% of Students

Recommend to friends

500,000+

Students Supported

50 Million+

Questions answered