Best Case for Bubble Sort

Yash picture Yash · Aug 31, 2009 · Viewed 49.1k times · Source

I want to know what will be the best case for a bubble sort ? There may be a case wherein there may be no swapping for the say last 2 passes for example. I'm doing my program in C language. Suppose i have an array of 5 elements and i give the elements as 1 2 5 4 3 then there would be no change in the last 2 passes?

Answer

jgallant picture jgallant · Aug 31, 2009

Best case scenario is one pass. The list would already be sorted.
No swap = done.