Sorting algorithms

EasyMediumHard
12345678910111213141516171819202122232425262728293031323334353637
Question 18
Medium

A smart-grid controller monitors five energy storage units with remaining capacities (in MWh) given by the array:

35142 \begin{array}{|c|c|c|c|c|} \hline 3 & 5 & 1 & 4 & 2 \\ \hline \end{array} 3​5​1​4​2​​

To prioritise charging, the controller uses the bubble sort algorithm to sort these capacities in ascending order.

Fill in the blank arrays below to show the steps involved in applying the bubble sort algorithm to the array. You only need to show the missing steps where a change (a swap) is applied to the array.

3514212345 \begin{array}{|c|c|c|c|c|} \hline 3 & 5 & 1 & 4 & 2 \\ \hline \quad & \quad & \quad & \quad & \quad \\ \hline \quad & \quad & \quad & \quad & \quad \\ \hline \quad & \quad & \quad & \quad & \quad \\ \hline \quad & \quad & \quad & \quad & \quad \\ \hline \quad & \quad & \quad & \quad & \quad \\ \hline 1 & 2 & 3 & 4 & 5 \\ \hline \end{array} 31​52​13​44​25​​
[5]

Sorting algorithms Questions

  1. GCSE
  2. /Computer Science
  3. /Sorting algorithms