# Bubble Sort Algorithm-Multiple Choice Question

Question

A Bubble Sort algorithm as discussed in lectures is given below

index1 = 1;

repeat exchange = false;

{ for index2 ← length – 1 downto index1

{ if data[index2] < data[index2-1]

{ //exchange

exchange = true;

tmp = data[index2];

data[index2] = data[index2-1];

data[index2-1] = tmp;

}

}

index1 = index1 + 1;

} until (not exchange)

Apply this algorithm to the following data. Give the contents of the array after each pass (repeat loop) is completed. For each pass how many exchanges are made?

Note it may not be necessary to use all 7 passes.

Original Data 14 27 12 56 63 72 8 10

After             Pass 1

Exchanges

After             Pass 2

Exchanges

After            Pass 3

Exchanges

After           Pass 4

Exchanges

After        Pass 5

Exchanges

After         Pass 6

Exchanges

After         Pass 7

Exchanges

How many comparisons will be made in total?

• Rasha

this is a very good website

• maani

I have 50 questions for the same test your page is showing only 28

• joeanne

• joeanne

hi can anyone help or guide me to my assignments. thanks

• Monik

• Cristina

This solution is perfect ...thanks

• Janete

Hello Allison,I love the 2nd image that you did! I also, had never heard of SumoPaint, is something that I will have to exolpre a bit! I understand completely the 52 (or so) youtube videos that you probably watched. Sometimes they have what you want, sometimes they don't! However, it is always satisfying when you are able to produce something that you have taught yourself. Great job!Debra 0 likes

• Sandeep

Perfect bank of solution.

• Oxana

great !

• Paul Brandon-Fritzius

thanks for the quick response. the solution looks good. :)

• tina Johnson

thnx for the answer. it was perfect. just the way i wanted it.

• Giuseppe

works fine.