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 )
When was UNESCO originally founded?
During his official visit to Greece, Prime Minister Narendra Modi received which prestigious award from the Greek government, becoming the first Foreign...
In October 2021, the Board of Control for Cricket in India (BCCI) unveiled Ahmedabad and _______ as the two new teams for the Indian Premier League (IPL...
Space Applications Centre (SAC) is located in which city of India?
What milestone was achieved by Ratapani Tiger Reserve in Madhya Pradesh?
What is the name of the first indigenously developed Light Combat Helicopter by HAL?
India’s first D2C foot-health focused footwear brand for children, Plaeto, has announced _____________ as its Brand Ambassador and Mentor.
Serdar Berdymukhamedov has recently been elected as president of which country?
Consider the following statements about scheduled banks.
I. Banks that are listed under Schedule II of the Reserve Bank of India Act, 1934.
<...Which organization approved American Express's new campus in Gurugram?