If you are using bubble sort for sorting the given numbers in acsending order then findout number of swappings needed. 7,6,5,8,9
Answers
Answered by
0
Answer:
Therefore, the number of swapping needed for arranging the numbers in ascending order is 12.
Answered by
0
The total number of swapping required for sorting the array= {7,6,5,8,9} in the acsending order is 3.
- In bubble sort, we iterate through whole arrays and compare value of adjacent pair of number, and swap if 2nd number is smaller than the first number.
- Array element : 7,6,5,8,9
- In the first iteration, the output will be 6,5,7,8,9 and total swaps are 2
- In the second iteration, the output will be 5,6,7,8,9 and total swaps are 1
- The array is now sorted after 2nd iteration. Therefore total swaps made are (2+ 1) = 3 . Total of three swaps are required to sort these number in ascending order using bubble sort.
Similar questions