edited by
866 views
1 votes
1 votes

Consider an array of elements $6 \ 4 \ 5 \ 3 \ 7 \ 1$. The contents of the array after three passes when we apply Bubble Sort on it is

  1. $3 \ 4 \ 1 \ 5 \ 6 \ 7$
  2. $3 \ 4 \ 5 \ 1 \ 6 \ 7$
  3. $3 \ 1 \ 4 \ 5 \ 6 \ 7$
  4. $3 \ 4 \ 5 \ 6 \ 1 \ 7$
edited by

1 Answer

Best answer
0 votes
0 votes

First Pass:               Second Pass:
6 4 5 3 7 1                4 5 3 6 1 7
4 6 5 3 7 1                4 5 3 6 1 7
4 5 6 3 7 1                4 3 5 6 1 7
4 5 3 6 7 1                4 3 5 6 1 7
4 5 3 6 7 1                4 3 5 1 6 7
4 5 3 6 1 7                4 3 5 1 6 7
 

Third Pass:
4 3 5 1 6 7
3 4 5 1 6 7
3 4 5 1 6 7
3 4 1 5 6 7
3 4 1 5 6 7
3 4 1 5 6 7
     
     so after 3 passes of Bubble Sort the final contents of the array is 3 4 1 5 6 7 .

selected by
Answer:

Related questions

0 votes
0 votes
1 answer
2
Bikram asked Nov 26, 2016
1,664 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