BS Pass 2

After this first pass the data is slightly more sorted than it was before. To further increase the ‘sortedness’ of the data, we can repeat the process. The first step of pass 2 is to compare the contents of element [0] with element [1]. In this example, 6 < 8, so the exchange is not made. The array stays unchanged at:

ADS 03 G

The second step of pass two is to compare element [1] with element [2]. We see that 7 > 6, so the exchange is made. This changes the array to:

ADS 03 I

The third step of pass two is to compare element [2] with element [3]. In this case 9 > 6, so the exchange is made:

ADS 03 J

If we take a simplistic approach to this problem, the fourth step of pass two is to compare element [3] with element [4]. It should be clear that the smallest element of the array is already in the final element (after the first pass) and a more sophisticated coding strategy will try to avoid unnecessary comparisons.

Next: BS Pass 3