Question
5,1,4,2,8 how many more pass are needed to finish
sorting by bubble sorting technique?Solution
First Pass: ( 5 1 4 2 8 ) –> ( 1 5 4 2 8 ), Here, algorithm compares the first two elements, and swaps since 5 > 1. ( 1 5 4 2 8 ) –> ( 1 4 5 2 8 ), Swap since 5 > 4 ( 1 4 5 2 8 ) –> ( 1 4 2 5 8 ), Swap since 5 > 2 ( 1 4 2 5 8 ) –> ( 1 4 2 5 8 ), Now, since these elements are already in order (8 > 5), algorithm does not swap them. Second Pass: ( 1 4 2 5 8 ) –> ( 1 4 2 5 8 ) ( 1 4 2 5 8 ) –> ( 1 2 4 5 8 ), Swap since 4 > 2 ( 1 2 4 5 8 ) –> ( 1 2 4 5 8 ) ( 1 2 4 5 8 ) –> ( 1 2 4 5 8 ) 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. Third Pass: ( 1 2 4 5 8 ) –> ( 1 2 4 5 8 ) ( 1 2 4 5 8 ) –> ( 1 2 4 5 8 ) ( 1 2 4 5 8 ) –> ( 1 2 4 5 8 ) ( 1 2 4 5 8 ) –> ( 1 2 4 5 8 )
Walmart-owned PhonePe has secured an additional $100 million investment from General Atlantic, a leading global growth equity firm, at a pre-money valua...
Who is the Author of the book “ ‘The Maverick Effect’?
According to a Reuters poll of economists, what was the expected consumer price inflation (CPI) for August 2024?
The Government has appointed Vinodanand Jha as New chairperson to &...
Where will the 2027 FIFA Women’s World Cup be hosted?
Which two organizations jointly launched the ‘We Rise’ initiative to support women entrepreneurs?
Which of the following ministries is the largest claimant for funds through Sovereign Green Bonds (SGBs) for green energy projects in India?
What was the value of content monetisation proposals generated at IndiaJoy B2B 2025?
____ social connecting app has launched one new feature ‘Communities’ to connect multiple group.
How much prize money will each of the 25 shortlisted teams receive for prototype development in Statathon?