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. 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
Study the following arrangement to answer the given questions.456 789 145 392 140 653 806 .If the above arrangement are arranged in the ascending order then what will be the middle number ?
I make up all the 55 digit numbers that use each of the digits from 11 to 55 once. I then arrange these 120120 numbers in increasing order from 1234512345 to 5432154321.Which number is the 4242nd in this order?
Which of the following are in descending order of their value ?1 , 2 , 3 , 4 , 5 , 63 5 7 5 6 71 , 2 , 3 , 4 , 5 , 63 5 5 7 6 71 , 2 , 3 , 4 , 5 , 63 5 5 6 7 76 , 5 , 4 , 3 , 2 , 17 6 5 7 5 3
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
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.