Linear Search vs Binary Search Comparison

Test yourself on Linear Search with exam style questions, marked instantly.

Flashcards that come back just before you would forget them.

A revision plan that remembers what you know and shows what to do next.

See which topics you have nailed and which need another look.

Quiz yourself on Linear SearchGet your flashcardsBuild my revision planTrack my progress

Linear Search vs Binary Search Comparison

Linear search and binary search for 18 in the sorted list 2, 5, 8, 12, 15, 18, 22, 25, shown as two panels. Linear search checks 2, 5, 8, 12 and 15, then finds 18 on check 6, so 6 comparisons. For 8 items the most it can need is 8 comparisons. Binary search checks the middle item 12 first, then the middle of the right half, which is 18, found on check 2, so 2 comparisons. For 8 items the most it can need is 4 comparisons.

Both searches look for 18 in the same sorted list. Linear search needs 6 checks and binary search needs 2. Binary search works only because the list is sorted. The gap grows with the list: for 1,000,000 items, linear search may need up to 1,000,000 checks and binary search at most 20.

Make this stick

Signing in gives access to all PrepWise features.

PrepWise is a trading name of A3M Quality Solutions Limited, registered in England and Wales, company number 14959172. Registered office: 202 Stroud Road, Gloucester, GL1 5LA. ICO registration ZC267069.