Ask Question
26 March, 06:31

In details and step-by-step, show how you apply the Bubble Sort algorithm on the following list of values. Your answer should show all inner and outer loops entries in each pass of the sort algorithm (i. e. list all 5 numbers in pass one, then list all 5 numbers in pass two, then list all 5 numbers in pass three ... etc.) 19, 18, 25, 17, 12

+5
Answers (1)
  1. 26 March, 06:40
    0
    (12 17 18 19 25)

    Explanation:

    First Pass:

    (19 18 25 17 12) - > (18 19 25 17 12), Here, algorithm compares the first two elements, and swaps since 19 > 18.

    (18 19 25 17 12) - > (18 19 25 17 12), Now, since these elements are already in order (25 > 19), algorithm does not swap them.

    (18 19 25 17 12) - > (18 19 17 25 12), Swap since 25 > 17

    (18 19 17 25 12) - > (18 19 17 12 25), Swap since 25 > 12

    Second Pass:

    (18 19 17 12 25) - > (18 19 17 12 25)

    (18 19 17 12 25) - > (18 17 19 12 25), Swap since 19 > 17

    (18 17 19 12 25) - > (18 17 12 19 25), Swap since 19 > 12

    (18 17 12 19 25) - > (18 17 12 19 25)

    Third Pass:

    (18 17 12 19 25) - > (17 18 12 19 25), Swap since 18 > 17

    (17 18 12 19 25) - > (17 12 18 19 25), Swap since 18 > 12

    (17 12 18 19 25) - > (17 12 18 19 25)

    (17 12 18 19 25) - > (17 12 18 19 25)

    Fourth Pass:

    (17 12 18 19 25) - > (12 17 18 19 25), Swap since 17 > 12

    (12 17 18 19 25) - > (12 17 18 19 25), Swap since 18 > 12

    (12 17 18 19 25) - > (12 17 18 19 25)

    (12 17 18 19 25) - > (12 17 18 19 25)

    Now, the array is already sorted, but our algorithm does not know if it is completed. The algorithm needs one whole pass without any swap to know it is sorted.

    Fifth Pass:

    (12 17 18 19 25) - > (12 17 18 19 25)

    (12 17 18 19 25) - > (12 17 18 19 25)

    (12 17 18 19 25) - > (12 17 18 19 25)

    (12 17 18 19 25) - > (12 17 18 19 25)
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “In details and step-by-step, show how you apply the Bubble Sort algorithm on the following list of values. Your answer should show all ...” in 📗 Engineering if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers