Bubble Sort in Swift

The classic sorting algorithm

Steven Curtis
3 min readMay 10, 2020
Photo by Zdeněk Macháček on Unsplash

Difficulty: Beginner* | Easy | Normal | Challenging

This article covers the classic sorting algorithm Bubble Sort in Swift.

  • This is seen as a beginner topic (first year Computer Science degree fare) but is certainly not easy.

Terminology

Algorithm: A process or set of rules to be followed

Big O Notation: A mathematical notation to describe the limiting behaviour of a function when an argument tends towards infinity

Bubble Sort: A sorting algorithm where the largest items bubble up one at a time

Sorting: Putting something into order. For example, to put 2,3,1 into order it would become 1,2,3.

Swap: The action of swapping two elements.

Bubble Sort

The Bubble Sort Algorithm is so called because elements tend to bubble up into the correct order, much like bubbles rising to the surface.

Bubble Sort is typically used for studying sorting rather than used in production code, and the implementation shown here is not recommended to be copied and pasted into production code under any circumstances!

The algorithm

--

--