Answer to Question #150840 in Algorithms for Rakibul

Question #150840
Let, AAA={34,12,56,22,43,60}
Apply bubble sort operation in AAA and show each step’s result for each pass value in
a table.
1
Expert's answer
2020-12-14T15:32:33-0500

Given,

AAA={34, 12, 56, 22, 43, 60}

In the bubble short, we are swapping the adjacent element if it is arranged in wrong order.

First Pass: {34, 12, 56, 22, 43, 60} Here, algorithm compares first two elements and swap, since 34>12

{12, 34, 56, 22, 43, 60} No swap, since 34<56

{12, 34, 22, 56, 43, 60} swap since 56>22

{12, 34, 22, 43, 56, 60} swap since 56>43

{12, 34, 22, 43, 56, 60} no swap because 56<60

Second Pass: {12, 34, 22, 43, 56, 60}

{12, 34, 22, 43, 56, 60} No swap, since 34>12

{12, 22, 34, 43, 56, 60} swap, since 34>22

{12, 22, 34, 43, 56, 60} swap, since 43>34

{12, 22, 34, 43, 56, 60} no swap, since 56>43

{12, 22, 34, 43,56, 60} no swap, since 60>56

Third Pass: {12, 22, 34, 43,56,60}

{12, 22, 34, 43,56,60} no swap, since 22>12

{12, 22, 34, 43,56,60} no swap, since 34>22

{12, 22, 34, 43,56,60} no swap, since 43>34

{12, 22, 34, 43,56,60} no swap, since 56>43

{12, 22, 34, 43,56,60} no swap, since 60>56


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS