Bubble sort
General Information
Algorithmic problem: Sorting based on pairwise comparison
Type of algorithm: loop
Abstract View
Invariant: After
Variant:
Break condition:
Induction Basis
Abstract view: Nothing to do.
Implementation: Nothing to do.
Proof: Nothing to show.
Induction Step
Abstract view: Step-by-step, move the maximum element seen so far to the position
Implementation: For
Correctness: The loop invariant of the inner loop is this: after
Pseudocode
BUBBLESORT(A)
1 for i = 1 to "A.length" - 1
2 for j = A.length downto i + 1
3 if A[j] < A[j - 1]
4 exchange A[j] with A[j - 1]
Complexity
Statemen: The asymptotic complexity is in
Proof: The asymptotic complexity of the inner loop in the