Computer Science, asked by keshireddysindhuredd, 2 months ago

If you are using bubble sort for sorting the given numbers in acsending order then findout number of swappings needed.3,10,4,7,9,2,6

Answers

Answered by shahegulafroz
13

Bubble Sort:

3 10 4 7 9 2 6

Bubble Sort:

Total 18 swapping required to get the bubble sort.

Answered by shilpa85475
8

Bubble sort is the simple sorting algorithm. It is used for arranging the values in ascending order which means comparing two adjacent values and rearranging them.

Given: 3 10 4 7 9 2 6

Start with the first two elements and compare. If the first value is greater than the second value then rearrange it. Repeatedly do this step for the numbers are in ascending order.

  1. 3 10 4 7 9 2 6
  2. 3 4 10 7 9 2 6
  3. 3 4 7 10 9 2 6
  4. 3 4 7 9 10 2 6
  5. 3 4 7 9 2 10 6
  6. 3 4 7 9 2 6 10
  7. 3 4 7 2 9 6 10
  8. 3 4 7 2 6 9 10
  9. 3 4 2 7 6 9 10
  10. 3 4 2 6 7 9 10
  11. 3 2 4 6 7 9 10
  12. 2 3 4 6 7 9 10

Therefore, the number of swapping needed for arranging the numbers in ascending order is 12.

Similar questions