The Gateway to Computer Science Excellence
0 votes
39 views

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 by Veteran (75k points)
edited by | 39 views

1 Answer

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 .

by Veteran (75k points)
selected by
Answer:

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,398 answers
198,613 comments
105,457 users