Academics · Study Skills · How the work grows as the list grows

How the work grows
with the list.

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 algorithm visualizer

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.

What you get

Academics · Study SkillsOpen to everyone · no sign-in

What you finish with
The most comparisons for linear search, binary search, bubble sort and merge sort on a list of n items, the time for each at your machine's speed and a table for lists from 10 items to a million.
Who it is for
High school and early college computer science students, and the families, teachers and tutors who help them learn why some algorithms scale and others do not.
Format
Browser calculator for a phone, tablet or computer, by touch or keyboard. Prints a summary; downloads a spreadsheet (.csv); export and import a file.
Access
Open to everyone with the link: no account, no sign-in, nothing to buy and nothing to install. Everything you type stays in this browser; nothing is sent to Caveat.
Where it lives
The Study Skills space in Caveat Academics.
Support
Questions, a correction or a request: team@caveatacademic.com.

How to use it

  1. Name the list.
  2. Type the number of items.
  3. Type the comparisons your computer makes in a second.
  4. Read the steps and times for each method.
  5. Scan the table to see how the counts grow with the list.

Count the steps

How the figures are worked out

Count the comparisons each method needs at most.

The worked example: a list of 1,000 itemsLinear search1,000steps at mostBinary search10halve 10 timesBubble sort499,500comparisonsMerge sort8,977comparisonsThe worked example: a list of 1,000 itemsLinear search1,000steps at mostBinary search10halve 10 timesBubble sort499,500comparisonsMerge sort8,977comparisons
Ten halvings find any item among 1,000, and merge sort beats bubble sort by about fifty to one.

Halve, halve, halve

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.

Why sort smartly

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.

Sources

  1. College Board. AP Computer Science Principles Course and Exam Description: Big Idea 3, Algorithms and Programming, on algorithm efficiency and binary search. apcentral.collegeboard.org.
  2. Knuth, D. E. (1998). The Art of Computer Programming, Volume 3: Sorting and Searching (2nd ed.). Addison-Wesley: comparison counts for binary search, bubble sort and merge sort.
  3. Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2022). Introduction to Algorithms (4th ed.). MIT Press: analysis of searching and sorting.
  4. Any introductory computer science text: linear and binary search, bubble sort and merge sort.

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.

Written with AI, then checked before it is published. How we checkFound a mistake? Report it and we fix it, or refund you.Cancel anytime.