Searching Algorithms Flashcards
(4 cards)
What is a linear search?
checks each item in a list one by one until it finds the one you’re looking for or reaches the end
What is a binary search?
A binary search quickly finds an item by repeatedly dividing the list in half and checking the middle value. If the item is smaller, it searches the left half; if bigger, the right half. It keeps going until it finds the item or the list can’t be divided anymore.
What is needed before using a binary search?
The list must be sorted in order (like from smallest to largest).
Why is binary search more efficient than linear search?
Binary search skips over large parts of the list by dividing it in half each time, so it needs fewer steps to find an item.