in Programming in C edited by
853 views
1 vote
1 vote

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$
in Programming in C edited by
by
853 views

1 Answer

0 votes
0 votes
Best answer

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