Lesson 12 of 23
Searching and Bubble Sort
11 min 30 XP
Bubble sort compares neighbours and swaps them when they're out of order; each pass bubbles the largest value to the end. Time complexity: O(n²).
Example: edit me and press Run
Output Loading C (first time takes a few seconds)
Press Run to see the result here.Binary search on a sorted array compares the middle element and discards half each time: O(log n), so even a million elements take about 20 steps!
Example: edit me and press Run
Output Loading C (first time takes a few seconds)
Press Run to see the result here.