🔄 Bubble Sort Pseudocode Guide for Beginners A step-by-step beginner-friendly guide to Bubble Sort Lim Jet Wee
How Bubble Sort Works Bubble Sort repeatedly compares two adjacent items in a list and swaps them if they are in the wrong order.
It 'bubbles' the largest value to the end of the list each time. Lim Jet Wee
📦 Full Pseudocode Lim Jet Wee
✅ Step 1: Understand the Problem You have a list (e.g., Temperature[1] to Temperature[10]) and want to sort it in ascending order using Bubble Sort. Lim Jet Wee
🧩 Step 2: Define Your Variables First ← 1 // The starting index of the list
Last ← 10 // The ending index of the list Lim Jet Wee
🔁 Step 3: Start a Repeat Loop REPEAT
Swap ← FALSE // Assume no swaps will happen in this pass
We use Swap to check if any items were swapped.
If no swaps, the list is already sorted. Lim Jet Wee
🔄 Step 4: Loop Through the List FOR Index ← First TO Last - 1
Loop through the list, comparing pairs of items. Lim Jet Wee
🔍 Step 5: Compare and Swap if Needed IF Temperature[Index] > Temperature[Index + 1] THEN
Temp ← Temperature[Index]
Temperature[Index] ← Temperature[Index + 1]
Temperature[Index + 1] ← Temp
Swap ← TRUE
ENDIF
If the current item is greater than the next one, swap them. Lim Jet Wee
🔚 Step 6: End the FOR Loop NEXT Index
Finish going through the list once. Lim Jet Wee
📉 Step 7: Shrink the Range Last ← Last - 1
After one full pass, the largest item is already in place, so reduce the range. Lim Jet Wee
🛑 Step 8: Check If Sorting is Done UNTIL (NOT Swap) OR Last = 1
Stop the loop if no swaps happened (list is sorted).
Also stop if only one item is left. Lim Jet Wee
📦 Full Pseudocode Lim Jet Wee
🧠 Summary for Students • Bubble Sort compares side-by-side values and swaps if needed.
• It repeats until the list is sorted.
• After each pass, the largest unsorted item is at its correct position at the end. Lim Jet Wee