\
  BubbleSort(A[],n)
    1.   For i = 0 to n - 1
    2.     For j = 0 to n - 1 - i
    3.       If A[j]>A[j+1]
    4.         swap A[j] <-> A[j+1]
    5.       End If
    6.     End For
    7.   End For
|
|
Space | ||
| Best Case | Average Case | Worst Case | |
What is the working mechanism of Bubble Sort, and what is
the origin of its name?
The bubble sort algorithm gets its name from the way that bubbles rise to the surface of a liquid - larger bubbles rise
faster - larger elements "rise" to their correct positions faster in the list. During each pass through the list,
adjacent elements are compared and swapped if necessary, gradually "sorting" the elements as if they were rising to the surface
like bubbles.
Is bubble sort a stable,
in-place sorting algorithm or an out-of-place sorting algorithm?
Bubble sort is a stable in-place algorithm, meaning that it does not require any extra space and maintains the relative order of duplicates.
How does the number of elements impact the efficiency of Bubble sort?
The efficiency of Bubble sort is impacted by the size of the input list, and as the list size increases,
the number of iterations needed for the algorithm to sort the list also increases, which can result in poor
performance when sorting large lists, making it unsuitable for large-scale applications.
What are advantages and disadvantages of Bubble Sort?
Advantages: