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 )
What new security feature did Punjab National Bank (PNB) introduce to combat cyber frauds?
Tripura Gramin Bank became India’s first Gramin Bank to introduce which innovative banking facility?Â
What is the penalty amount imposed by RBI on Federal Bank Ltd and Karur Vysya Bank Ltd for non-compliance with regulations?
What is the name of the first semi-high-speed rail corridor project approved for Maharashtra in February 2025?
The Reserve Bank of India (RBI) has set up a Regulatory Review Cell (RRC) to review rules periodically. After how many years will the regulations be rev...
What is the main purpose of the SBI Innovation Hub launched at the Singapore Fintech Festival?
How many science nodes will be connected by the INCOIS submarine cable in the Indian Ocean?
India’s foreign exchange reserves dropped to what value for the week ending October 18, 2024?
- How does the India-Qatar Joint Business Forum aim to enhance economic cooperation?
- Under the PM-KISAN scheme, how much annual financial assistance is provided to eligible farmers?