0% found this document useful (0 votes)
53 views

Bubble Sort: Pass 1: 1.1

The document describes applying bubble sort to sort an array of numbers. It goes through 3 passes of the bubble sort algorithm, comparing and swapping adjacent elements if out of order. After the 3 passes, the array is fully sorted from lowest to highest.

Uploaded by

shoeb_sohel
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

Bubble Sort: Pass 1: 1.1

The document describes applying bubble sort to sort an array of numbers. It goes through 3 passes of the bubble sort algorithm, comparing and swapping adjacent elements if out of order. After the 3 passes, the array is fully sorted from lowest to highest.

Uploaded by

shoeb_sohel
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 19

Bubble sort

The following numbers are stored in an array A: 8, 4, 2, 9, 7, 5 We will apply Bubble Sort to the array A.

Pass 1:
1.1
8 4 2 9 7 5 Compare the first two elements of array A, if first element is greater then the second element, interchange them.

1.2
8 4 2 9 7 5 The position of 8 & 4 is interchanged as 8 is greater then 4.

4 8 2 9 7 5

Compare the next two elements of the array, if the first element is greater then the second element interchange them, else it will remain as it is.

1.3
4 8 2 9 7 5 The position of 8 & 2 is interchanged as 8 is greater then 2.

4 2 8 9 7 5 Compare the next two elements of the array, if the first element is greater then the second element interchange them, else it will remain as it is.

1.4
4 2 8 9 7 5 The position of 8 & 9 will remain as it is as 8 is smaller then 9.

4 2 8 9 7 5

Compare the next two elements of the array, if the first element is greater then the second element interchange them, else it will remain as it is.

1.5
4 2 8 9 7 5 The position of 9 & 7 is interchanged as 7 is smaller then 9.

4 2 8 7 9 5 Compare the next two elements of the array, if the first element is greater then the second element interchange them, else it will remain as it is.

1.6
4 2 8 9 7 5 The position of 7 & 5 is interchanged as 5 is smaller then 7.

4 2 8 7 5 9 The final Array after Pass 1

Pass 2: 2.1
4 2 8 7 5 9 Compare the next two elements of the array, if the first element is greater then the second element interchange them, else it will remain as it is.

2.2
4 2 8 The position of 4 & 2 is interchanged as 4 is greater then 2.

7
5 9

2 4 8 7 5 9

Compare the next two elements of the array, if the first element is greater then the second element interchange them, else it will remain as it is.

2.3
2 4 8 7 5 9

The position of 4 & 8 will remain as it is as 4 is smaller then 8.

2 4
8 7 5 9 Compare the next two elements of the array, if the first element is greater then the second element interchange them, else it will remain as it is.

2.4
2 4 8

The position of 8 & 7 is interchanged as 8 is greater then 7.

7
5 9

2 4
7 8 5 9 Compare the next two elements of the array, if the first element is greater then the second element interchange them, else it will remain as it is.

2.5
2 4 7 8 5 9 The position of 8 & 5 is interchanged as 8 is greater then 5.

2 4 7 5 8 9 Compare the next two elements of the array, if the first element is greater then the second element interchange them, else it will remain as it is.

2.6
2 4 7

5
8 9 The position of 8 & 9 will remain as it is as 8 is smaller then 9.

2 4
7 5 8 9 The final Array after Pass 2

Pass 3: 3.1
2 4 7 5 8 9

Compare the first two elements of the array, if the first element is greater then the second element interchange them, else it will remain as it is.

3.2
2 4 7 5 8 9 The position of 2 & 4 will remain as it is as 2 is smaller then 4.

2 4 7 5 8 9

Compare the next two elements of the array, if the first element is greater then the second element interchange them, else it will remain as it is.

3.3
2 4 7 5 8 9 The position of 4 & 7 will remain as it is as 4 is smaller then 7.

2 4 7 5 8 9 Compare the first two elements of the array, if the first element is greater then the second element interchange them, else it will remain as it is.

3.4
2 4 7 5 8 9

The position of 7 & 5 will interchange as 7 is greater then 5.

2 4 5 7 8 9 Compare the next two elements of the array, if the first element is greater then the second element interchange them, else it will remain as it is.

3.5
2 4 5 7 8 9 The position of 7 & 8 will remain as it is as 7 is smaller then 8.

2 4
5 7 8 9 Compare the first two elements of the array, if the first element is greater then the second element interchange them, else it will remain as it is.

3.6
2 4 5 7 8 9 The position of 8 & 9 will remain as it is as 8 is smaller then 9.

4
5 7 8 9 The final Array after Pass 3

Final Sorted Array


2 4 5 7 8 9

You might also like