Professional Documents
Culture Documents
Algorithm MYP 5
Algorithm MYP 5
Algorithm MYP 5
Start from the beginning of the list and compare each pair of adjacent elements.
Continue iterating through the list, comparing and swapping adjacent elements until
no more swaps are needed.
Pass 1: Compare and swap (5, 2), (5, 9), (9, 1), (9, 5). Updated list: [2, 5, 1, 5, 9].
Pass 2: Compare and swap (2, 5), (5, 1), (5, 9). Updated list: [2, 1, 5, 5, 9].
Pass 3: Compare and swap (2, 1), (2, 5), (5, 5). Updated list: [1, 2, 5, 5, 9].
The sorted list is [1, 2, 5, 5, 9]. Bubble Sort is a simple sorting algorithm, and while it
may not be the most efficient for large datasets, it is well-defined and demonstrates
the concept of analyzing and using well-defined procedures for solving problems.
Set r = a % b (where % denotes the modulus operator, i.e., the remainder when a is
divided by b).
Set a = b and b = r.