Tutorials › Launch Lab Notes › Chapter 28

Three Sorts, One Array

LabChapter 28 of the Launch Lab Notes20 minAugust 20, 2026Intermediate

Algorithms argue in big-O. This bench argues in CMP.

One fixed shuffle. Three instruments. Bubble is the control — it is allowed to be wasteful so the others have something to beat.

Filmstrip: same shuffle; BUBBLE CMP climbs hardest while MERGE and QUICK finish with fewer comparisons.

Start — identical bars

-mode start

SEED 7 2 11 4 9 1 12 5 8 3 10 6. BUBBLE MERGE QUICK all CMP 0 racing. STEP 0/66.
SEED7 2 11 4 9 1 12 5 8 3 10 6
STEP0 / 66
CMP0 / 0 / 0

Mid — bubble still climbing

-mode mid → step 22 / 66

STEP 22/66. BUBBLE CMP 22 racing. MERGE CMP 15. QUICK CMP 18. Bars partially ordered.
AlgorithmCMP @ step 22Status
BUBBLE (control)22racing
MERGE15racing
QUICK18racing

Same wall-clock step index. Bubble has already spent more compares than merge will need in total later.

Done — the meter that matters

-mode done

All DONE ascending bars. BUBBLE CMP 66. MERGE CMP 32. QUICK CMP 28. STEP 66/66.
AlgorithmFinal CMP
BUBBLE66control
MERGE32
QUICK28

All three bars read 1…12. Only the comparison counters disagree — and they disagree by more than 2×.

n = 12 is enough to photograph

Bubble’s 66 is exactly 12×11/2 adjacent passes. Merge and quick land near n log n territory on this seed. The control is not “wrong” — it is the expensive baseline the chapter is about.

Mini-exercise

Reverse the seed to 12…1. Re-run -mode done and watch bubble’s CMP stay 66 while quick’s partition counts move.

Challenges

  1. Add insertion sort as a fourth column and compare its CMP to bubble.
  2. Instrument swaps separately and show SWAP beside CMP.
  3. Highlight the two indices involved in the latest comparison.
  4. Race on n = 32 and photograph how bubble’s frame count explodes.
  5. XCUITest: assert CMP 66 appears under -mode done.

Key Points

Queue empty — the editorial list in lab-queue.json is cleared. Further Lab chapters need new queue entries.

SwiftUI
SwiftUI tutorials for building native app screens, layouts, navigation, and state-driven interfaces.
Swift
Swift fundamentals for app developers who want to understand the language behind real iOS and macOS apps.
Ship iOS
Shipping workflows for iOS apps.
📚 Go deeper with LIPAI WANG’s hands-on Udemy bootcampsBrowse all courses →
← Ch 27: The Entries AheadComing Soon →
SwiftUIUltimate SwiftUI SeriesSwiftUI tutorials for building native app screens, layouts, navigation, and state-driven interfaces.SwiftUltimate Swift SeriesSwift fundamentals for app developers who want to understand the language behind real iOS and macOS apps.Ship iOSShip iOS Apps SeriesShipping workflows for iOS apps: signing, TestFlight, App Store Connect, CI, and release hygiene.

Ship your apps faster

When you're ready to publish your Swift app to the App Store, Simple App Shipper handles metadata, screenshots, TestFlight, and submissions — all in one place.

Try Simple App Shipper
5 free articles remainingSubscribe for unlimited access