Bubble Sort
Generate Random Values
Enter the number of random values to generate
Input Your Own Values
Enter a list of numbers separated by a comma
Whats goin on?
Bubble sort is an algorithm that repeatedly iterates through an array. It begins on the first element and compares it to the element after it. If the that element is smaller than the current one, swap the two. If the next element happens to be larger than the current one, increment the current element to the next position. Repeating this process should eventually yield a sorted array. Once there has been an iteration with no swaps, it can be assumed that the array is sorted and the program stops immediately.
Performance
Time complexity
Because each iteration has an additional iteration through the array, the time complexity of bubble sort is
O(n^2)
Space complexity
Bubble sort only needs one additional space in memory to perform the swap so its space complexity is
O(1)