Consider the given numbers and arrange in an increasing order using sorting algorithm. Show all the sweeps. 80 9 30 20 7
Question
Consider the given numbers and arrange in an increasing order using sorting algorithm. Show all the sweeps.
Numbers:
80
9
30
20
7
Solution
Sure, we can use the Bubble Sort algorithm to arrange the numbers in increasing order. Here are the steps:
Initial Array: 80 9 30 20 7
First Sweep: Compare 80 and 9, since 80 > 9, swap them: 9 80 30 20 7 Compare 80 and 30, since 80 > 30, swap them: 9 30 80 20 7 Compare 80 and 20, since 80 > 20, swap them: 9 30 20 80 7 Compare 80 and 7, since 80 > 7, swap them: 9 30 20 7 80
Second Sweep: Compare 9 and 30, since 9 < 30, no swap: 9 30 20 7 80 Compare 30 and 20, since 30 > 20, swap them: 9 20 30 7 80 Compare 30 and 7, since 30 > 7, swap them: 9 20 7 30 80
Third Sweep: Compare 9 and 20, since 9 < 20, no swap: 9 20 7 30 80 Compare 20 and 7, since 20 > 7, swap them: 9 7 20 30 80
Fourth Sweep: Compare 9 and 7, since 9 > 7, swap them: 7 9 20 30 80
Now, the array is sorted in increasing order: 7 9 20 30 80
Similar Questions
Sort the given list of numbers in ascending order. Demonstrate the first pass/sweep sort algorithm. 43 18 9 76 89 1
Write a program using C language that sorts the 10 rollno,s of your class placed in an array of size 10?Input:87109132546 Output:12345678910
Give the result of bubble sort after fifth pass {94,78,65,45,58,72,63,12,18}and also write a function to implement bubble sort
What will be the number of passes to sort the elements using insertion sort?14, 12,16, 6, 3, 10
What will be the number of passes to sort the elements using insertion sort?14, 12,16, 6, 3, 106571
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.