if you're using a bubble sort for sorting the given numbers in ascending order they find out the number of swapping needed 25,28,22,18,16
Answers
Answer:
16,18,22,25,28
Step-by-step explanation:
because the ascending order means first to last than that I do first to last 16.18.22.25.28.
Bubble Sort
Given:
Numbers are given 25,28,22,18,16
To Find:
Number of swapping needed to arrange these numbers in ascending order.
Explanation:
The iterations are as follows:
1st iteration: 25,28,22,18,16 (swap 25 and 28 in ascending order, here they are already in ascending order)
2nd iteration: 25, 22, 28,18,16 (swap 22 and 28)
3rd iteration: 25,22,18,28,16 (swap 28 and 18)
4th iteration:25,22,18,16,28 (swap 16 and 28)
5th iteration: 22, 25, 18,16,28 (swap 22 and 25)
6th iteration: 22,18,25,16,28 (swap 18 and 25)
7th iteration:22,18,16,25,28 (swap 16 and 25)
8th iteration:22, 18, 16, 25, 28( no swap needed for 25 and 28)
9th iteration: 18, 22, 16, 25, 28( swap 18 and 28)
10th iteration: 18, 16, 22, 25, 28(swap 16 and 22)
11th iteration:18, 16, 22, 25, 28(no swap needed for 22 and 25)
12th iteration: 18, 16, 22,25,28(no swap needed for 25 and 28)
13th iteration: 16, 18, 22, 25, 28(swap 16 and 18)
So, 13 swapping is needed.