edited by
180 views
2 votes
2 votes

The resultant array after first iteration of bubble sort on $10,20,6,5,30, 8$  is _________.

  1. $10 , 6,5,20,8,30$
  2. $10 , 6,5,20,30,8$
  3. $10 , 5,6,20,8,30$
  4. $10 , 6,5,30,8,20$
edited by

1 Answer

Best answer
1 votes
1 votes
In Bubble sort, when the first pass(iteration)  is completed largest element goes to the last position.

 $10,20,6,5,30,8$

Compare each element one by one,and if first_element > second_element, then swap the elements.Otherwise no swapping.

 $10,20,6,5,30,8$

 $10,6,20,5,30,8$

 $10,6,5,20,30,8$

 $10,6,5,20,30,8$

 $10,6,5,20,8,30$

Option $(A)$ is the correct answer.
selected by
Answer:

Related questions

0 votes
0 votes
1 answer
2
Bikram asked Nov 26, 2016
1,637 views
Three algorithms do the same task. Algorithm One is $O(N)$ and Algorithm Two is $O(\log N)$ and Algorithm Three is $O(N1/2)$. Which algorithm should execute the fastest f...
1 votes
1 votes
3 answers
3
0 votes
0 votes
0 answers
4