Bubblesort (Exercise)

Objective

In this experiment, you need to drive the the Bubblesort algorithm using the given controls. The system will warn you if the step does not correspond to the one taken by the Bubblesort algorithm.

Experiment Setup

The experiment consists of a list of numbers and four controls: Swap, Increment i, Reset i and Decrement b. Selection of the list elements is controlled by the value of i, not by clicking the elements. The two variables i and b mark the values of current index and boundary variables of the Bubblesort algorithm.

  1. The Swap button swaps the element at i with the element at i+1.
  2. Increment i increments the value of i. It does not swap the elements if they are out of order.
  3. Reset i resets the value of i to 0.
  4. Decrement b reduces the value of b by 1.

Procedure

Follow the given steps to perform the experiment.

  1. Click a suitable control to simulate the next step of Bubblesort
  2. Check if the feedback box indicates that you have made a mistake or if you need to continue (even if the array is sorted). Repeat step 1 till you finish simulating bubblesort. At the end, b should have the value 1 and i should be 0.