Academics · Study Skills · How the work grows as the list grows
Two ways of finding an item in a list can differ by a thousand to one, and two ways of sorting by more. Type the number of items and the steps your computer runs each second. The page counts the most comparisons linear search, binary search, bubble sort and merge sort need, turns each into a time and shows the lists from 10 items to a million.
The worked example is a sorted list of 1,000 items on a computer that makes a million comparisons a second. Nothing you type leaves this browser.
Loading the calculator. If nothing appears, turn on JavaScript.
Steps are comparisons. The example is made up.
Academics · Study SkillsOpen to everyone · no sign-in
Count the comparisons each method needs at most.
Binary search compares the target with the middle of a sorted list and keeps only the half that could hold it. A list of a million items is cut to one in 20 steps. The AP Computer Science Principles framework expects students to compare the efficiency of algorithms, including linear and binary search, by the number of steps they take as the input grows.
Bubble sort does about n squared ÷ 2 comparisons, so doubling the list quadruples the work. Merge sort does about n log n, which grows only a little faster than the list does. For a million items that is the difference between hours and a fraction of a second at the same speed.
Figures worked from your own numbers. Nothing you type is sent to Caveat. The worked example is made up. Your entries stay in this browser. Support: team@caveatacademic.com.