How many passes are required in bubble sort?
The number of required passes in bubble sort or How many passes are required in bubble sort?
In bubble sort , the minimum passes are required is 1 or the maximum passes are required is n-1. The pass are used in bubble sorts are sorting the elements repeated until the element is sorted.
If the list of the element is already sorted the sort can stop.
If you have a list of unsorted element and you want to sort the list of these element then you can uses the passes algorithm.
the passes algorithm compares first two number if the first number is greater than the second number then swap these number but if the first number is less than the second number then you can compare next two number because the number is already sorted.
Let’s See an example of it how it works :
you have a list of element that is [6,2,3,4,8]
Step 1: compare first two element that is 6>2. then swap these number and updated list of element id [2,6,3,4,8].
Step2 : compare next two number. 6>3. then swap these number and updated list of element is [2,3,6,4,8]
Step3: compare next two element is 6>4 that is true so swap these number and updated list of element is [2,3,4,6,8]
Step4: and this is the last step compare next element. 6>8 that is false so we can’t swap these number because it is already sorted and the finally sorting is [2,3,4,6,8]
In this step you can see how many are required in bubble sort. I hope it helps you.
Comments
Post a Comment