Bubble sort analysis
Rating
About video
Bubble sort has a worst-case and average complexity of о(n ), where n is the number of items being sorted. Most practical sorting algorithms have substantially better worst-case or average complexity, often o(n log n). Even other о(n ) sorting algorithms, such as insertion sort, generally run faster than bubble sort, and are no more complex. (n - 1) n(n - 1)2 o(n 2) clearly, the graph shows the n 2 nature of the bubble sort. In this algorithm, the number of comparison is irrespective of the data set, i. Whether the provided input elements are in sorted order or in reverse order or at random. boundary cases bubble sort takes minimum time (order of n) when elements are already sorted. Due to its simplicity, bubble sort is often used to introduce the concept of a sorting algorithm. Lets first talk about the non-optimized version of the bubble sort. Regardless of the input, the two loops and the if statements are going to execute every time. Only the execution of the swap statement will depend upon the input. Analyze the exact amount of comparisons and swaps for the best, average, and worst case of bubble sort.