Skip to content
0:00 / 0:00

#bubblesort#timecomplexity#bigonotation

Bubble Sort Worst And Best Case

randerson112358

19K subscribers • 1 video on Hallway

YouTube

Beginner. No background in the topic needed.

14K views9 years ago1 recommendation

Computer scienceAlgorithmsData structuresComputation and complexity

How the best and worst-case time complexities of the Bubble Sort algorithm are analyzed using a C implementation.

This is one way of writing the Bubble Sort Algorithm in C. There are other ways to create this algorithm that will give you a better Best Case, like O(n). This algorithm gives the best case of O(n^2). Get the code here: github.com/randerson112358/C-Programs/blob/master/BubbleSort… Easy Algorithm Analysis Tutorial: udemy.com/algorithm-analysis/ Please Subscribe ! ►Website: everythingcomputerscience.com/ ►Support this channel on Patreon: patreon.com/randerson112358 Sources: stackoverflow.com/questions/1358383/best-case-for-bubble-sor…

Why it's here

1 person recommends this

What people say. Recommended for understanding why certain implementations of bubble sort have an O(n^2) best-case complexity.

tempmailon Stack Overflow • Recommends

On “Best Case for Bubble Sort”

There are multiple ways to write the bubble sort algorithm, it seems like over time the algorithm has gotten better, and more efficient. The first bubble sort algorithm I learned is below. The algorithm below Best and Worst Case is O(n^2). BUBBLESORT(A) 1 for i = 1 to A.length - 1 2 for j = A.length downto i + 1 3 if Aj < Aj - 1 4 exchange Aj with Aj - 1 The algorithm that Wikipedia uses (below) seems to be an improvement using a flag to tell if the elements have been swapped or not, which allows the bubble sort algorithm best case to be O(n) instead of O(n^2) procedure bubbleSort( A : list of sortable items ) n = length(A) repeat swapped = false for i = 1 to n-1 inclusiv…