Sort the given sequence of numbers using Bubble sort. Write all the
steps involved. 13, 15, 2, 6, 14, 10, 8, 7, 3, 5, 19, 4.
Initial array:
13, 15, 2, 6, 14, 10, 8, 7, 3, 5, 19, 4
First pass:
13, 15, 2, 6, 14, 10, 8, 7, 3, 5, 19, 4 (13 < 15)
13, 2, 15, 6, 14, 10, 8, 7, 3, 5, 19, 4 (15 <=> 2)
13, 2, 6, 15, 14, 10, 8, 7, 3, 5, 19, 4 (15 <=> 6)
13, 2, 6, 14, 15, 10, 8, 7, 3, 5, 19, 4 (15 <=> 14)
13, 2, 6, 14, 10, 15, 8, 7, 3, 5, 19, 4 (15 <=> 10)
13, 2, 6, 14, 10, 8, 15, 7, 3, 5, 19, 4 (15 <=> 8)
13, 2, 6, 14, 10, 8, 7, 15, 3, 5, 19, 4 (15 <=> 7)
13, 2, 6, 14, 10, 8, 7, 3, 15, 5, 19, 4 (15 <=> 3)
13, 2, 6, 14, 10, 8, 7, 3, 5, 15, 19, 4 (15 <=> 5)
13, 2, 6, 14, 10, 8, 7, 3, 5, 15, 19, 4 (15 < 19)
13, 2, 6, 14, 10, 8, 7, 3, 5, 15, 4, 19 (19 <=> 4)
Secont pass:
2, 13, 6, 14, 10, 8, 7, 3, 5, 15, 4, 19 (13 <=> 2)
2, 6, 13, 14, 10, 8, 7, 3, 5, 15, 4, 19 (13 <=> 6)
2, 6, 13, 14, 10, 8, 7, 3, 5, 15, 4, 19 (13 < 14)
2, 6, 13, 10, 14, 8, 7, 3, 5, 15, 4, 19 (14 <=> 10)
2, 6, 13, 10, 8, 14, 7, 3, 5, 15, 4, 19 (14 <=> 8)
2, 6, 13, 10, 8, 7, 14, 3, 5, 15, 4, 19 (14 <=> 7)
2, 6, 13, 10, 8, 7, 3, 14, 5, 15, 4, 19 (14 <=> 3)
2, 6, 13, 10, 8, 7, 3, 5, 14, 15, 4, 19 (14 <=> 5)
2, 6, 13, 10, 8, 7, 3, 5, 14, 15, 4, 19 (14 < 15)
2, 6, 13, 10, 8, 7, 3, 5, 14, 4, 15, 19 (15 <=> 4)
2, 6, 13, 10, 8, 7, 3, 5, 14, 4, 15, 19 (15 < 19)
Third pass:
2, 6, 13, 10, 8, 7, 3, 5, 14, 4, 15, 19 (2 < 6)
2, 6, 13, 10, 8, 7, 3, 5, 14, 4, 15, 19 (6 < 13)
2, 6, 10, 13, 8, 7, 3, 5, 14, 4, 15, 19 (13 <=> 10)
2, 6, 10, 8, 13, 7, 3, 5, 14, 4, 15, 19 (13 <=> 8)
2, 6, 10, 8, 7, 13, 3, 5, 14, 4, 15, 19 (13 <=> 7)
2, 6, 10, 8, 7, 3, 13, 5, 14, 4, 15, 19 (13 <=> 3)
2, 6, 10, 8, 7, 3, 5, 13, 14, 4, 15, 19 (13 <=> 5)
2, 6, 10, 8, 7, 3, 5, 13, 14, 4, 15, 19 (13 < 14)
2, 6, 10, 8, 7, 3, 5, 13, 4, 14, 15, 19 (14 <=> 4)
2, 6, 10, 8, 7, 3, 5, 13, 4, 14, 15, 19 (14 < 15)
2, 6, 10, 8, 7, 3, 5, 13, 4, 14, 15, 19 (15 < 19)
Fourth pass:
2, 6, 10, 8, 7, 3, 5, 13, 4, 14, 15, 19 (2 < 6)
2, 6, 10, 8, 7, 3, 5, 13, 4, 14, 15, 19 (6 < 10)
2, 6, 8, 10, 7, 3, 5, 13, 4, 14, 15, 19 (10 <=> 8)
2, 6, 8, 7, 10, 3, 5, 13, 4, 14, 15, 19 (10 <=> 7)
2, 6, 8, 7, 3, 10, 5, 13, 4, 14, 15, 19 (10 <=> 3)
2, 6, 8, 7, 3, 5, 10, 13, 4, 14, 15, 19 (10 <=> 5)
2, 6, 8, 7, 3, 5, 10, 13, 4, 14, 15, 19 (10 < 13)
2, 6, 8, 7, 3, 5, 10, 4, 13, 14, 15, 19 (13 <=> 4)
2, 6, 8, 7, 3, 5, 10, 4, 13, 14, 15, 19 (13 < 14)
2, 6, 8, 7, 3, 5, 10, 4, 13, 14, 15, 19 (14 < 15)
2, 6, 8, 7, 3, 5, 10, 4, 13, 14, 15, 19 (15 < 19)
Fit=fth pass:
2, 6, 8, 7, 3, 5, 10, 4, 13, 14, 15, 19 (2 < 6)
2, 6, 8, 7, 3, 5, 10, 4, 13, 14, 15, 19 (6 < 8)
2, 6, 7, 8, 3, 5, 10, 4, 13, 14, 15, 19 (8 <=> 7)
2, 6, 7, 3, 8, 5, 10, 4, 13, 14, 15, 19 (8 <=> 3)
2, 6, 7, 3, 5, 8, 10, 4, 13, 14, 15, 19 (8 <=> 5)
2, 6, 7, 3, 5, 8, 10, 4, 13, 14, 15, 19 (8 < 10)
2, 6, 7, 3, 5, 8, 4, 10, 13, 14, 15, 19 (10 <=> 4)
2, 6, 7, 3, 5, 8, 4, 10, 13, 14, 15, 19 (10 < 13)
2, 6, 7, 3, 5, 8, 4, 10, 13, 14, 15, 19 (13 < 14)
2, 6, 7, 3, 5, 8, 4, 10, 13, 14, 15, 19 (14 < 15)
2, 6, 7, 3, 5, 8, 4, 10, 13, 14, 15, 19 (15 < 19)
Sixth pass:
2, 6, 7, 3, 5, 8, 4, 10, 13, 14, 15, 19 (12 < 6)
2, 6, 7, 3, 5, 8, 4, 10, 13, 14, 15, 19 (6 < 7)
2, 6, 3, 7, 5, 8, 4, 10, 13, 14, 15, 19 (7 <=> 3)
2, 6, 3, 5, 7, 8, 4, 10, 13, 14, 15, 19 (7 <=> 5)
2, 6, 3, 5, 7, 8, 4, 10, 13, 14, 15, 19 (7 < 8)
2, 6, 3, 5, 7, 4, 8, 10, 13, 14, 15, 19 (8 <=> 4)
2, 6, 3, 5, 7, 4, 8, 10, 13, 14, 15, 19 (8 < 10)
2, 6, 3, 5, 7, 4, 8, 10, 13, 14, 15, 19 (10 < 13)
2, 6, 3, 5, 7, 4, 8, 10, 13, 14, 15, 19 (13 < 14)
2, 6, 3, 5, 7, 4, 8, 10, 13, 14, 15, 19 (14 < 15)
2, 6, 3, 5, 7, 4, 8, 10, 13, 14, 15, 19 (15 < 19)
Seventh pass:
2, 6, 3, 5, 7, 4, 8, 10, 13, 14, 15, 19 (2 < 6)
2, 3, 6, 5, 7, 4, 8, 10, 13, 14, 15, 19 (6 <=> 3)
2, 3, 5, 6, 7, 4, 8, 10, 13, 14, 15, 19 (6 <=> 5)
2, 3, 5, 6, 7, 4, 8, 10, 13, 14, 15, 19 (6 < 7)
2, 3, 5, 6, 4, 7, 8, 10, 13, 14, 15, 19 (7 <=> 4)
2, 3, 5, 6, 4, 7, 8, 10, 13, 14, 15, 19 (7 < 8)
2, 3, 5, 6, 4, 7, 8, 10, 13, 14, 15, 19 (8 < 10)
2, 3, 5, 6, 4, 7, 8, 10, 13, 14, 15, 19 (10 < 13)
2, 3, 5, 6, 4, 7, 8, 10, 13, 14, 15, 19 (13 < 14)
2, 3, 5, 6, 4, 7, 8, 10, 13, 14, 15, 19 (14 < 15)
2, 3, 5, 6, 4, 7, 8, 10, 13, 14, 15, 19 (15 < 19)
Eighth pass:
2, 3, 5, 6, 4, 7, 8, 10, 13, 14, 15, 19 (2 < 3)
2, 3, 5, 6, 4, 7, 8, 10, 13, 14, 15, 19 (3 < 5)
2, 3, 5, 6, 4, 7, 8, 10, 13, 14, 15, 19 (5 < 6)
2, 3, 5, 4, 6, 7, 8, 10, 13, 14, 15, 19 (6 <=> 4)
2, 3, 5, 4, 6, 7, 8, 10, 13, 14, 15, 19 (6 < 7)
2, 3, 5, 4, 6, 7, 8, 10, 13, 14, 15, 19 (7 < 8)
2, 3, 5, 4, 6, 7, 8, 10, 13, 14, 15, 19 (8 < 10)
2, 3, 5, 4, 6, 7, 8, 10, 13, 14, 15, 19 (10 < 13)
2, 3, 5, 4, 6, 7, 8, 10, 13, 14, 15, 19 (13 < 14)
2, 3, 5, 4, 6, 7, 8, 10, 13, 14, 15, 19 (14 < 15)
2, 3, 5, 4, 6, 7, 8, 10, 13, 14, 15, 19 (15 < 19)
Ninth pass:
2, 3, 5, 4, 6, 7, 8, 10, 13, 14, 15, 19 (2 < 3)
2, 3, 5, 4, 6, 7, 8, 10, 13, 14, 15, 19 (3 < 5)
2, 3, 4, 5, 6, 7, 8, 10, 13, 14, 15, 19 (5 <=> 4)
2, 3, 4, 5, 6, 7, 8, 10, 13, 14, 15, 19 (5 < 6)
2, 3, 4, 5, 6, 7, 8, 10, 13, 14, 15, 19 (6 < 7)
2, 3, 4, 5, 6, 7, 8, 10, 13, 14, 15, 19 (7 < 8)
2, 3, 4, 5, 6, 7, 8, 10, 13, 14, 15, 19 (8 < 10)
2, 3, 4, 5, 6, 7, 8, 10, 13, 14, 15, 19 (10 < 13)
2, 3, 4, 5, 6, 7, 8, 10, 13, 14, 15, 19 (13 < 14)
2, 3, 4, 5, 6, 7, 8, 10, 13, 14, 15, 19 (14 < 15)
2, 3, 4, 5, 6, 7, 8, 10, 13, 14, 15, 19 (15 < 19)
Tenth pass:
2, 3, 4, 5, 6, 7, 8, 10, 13, 14, 15, 19 (1 < 2)
2, 3, 4, 5, 6, 7, 8, 10, 13, 14, 15, 19 (2 < 3)
2, 3, 4, 5, 6, 7, 8, 10, 13, 14, 15, 19 (3 < 4)
2, 3, 4, 5, 6, 7, 8, 10, 13, 14, 15, 19 (4 < 6)
2, 3, 4, 5, 6, 7, 8, 10, 13, 14, 15, 19 (6 < 7)
2, 3, 4, 5, 6, 7, 8, 10, 13, 14, 15, 19 (7 < 8)
2, 3, 4, 5, 6, 7, 8, 10, 13, 14, 15, 19 (8 < 10)
2, 3, 4, 5, 6, 7, 8, 10, 13, 14, 15, 19 (10 < 13)
2, 3, 4, 5, 6, 7, 8, 10, 13, 14, 15, 19 (13 < 14)
2, 3, 4, 5, 6, 7, 8, 10, 13, 14, 15, 19 (14 < 15)
2, 3, 4, 5, 6, 7, 8, 10, 13, 14, 15, 19 (15 < 19)
No swaps - the array is sorted
Comments
Leave a comment