Searching

Algorithms
process

Also known as: search algorithm

Grade 9-12

View on concept map

The process of locating a specific item or value within a collection of data using a systematic strategy. Searching is one of the most common operations in computing.

Definition

The process of locating a specific item or value within a collection of data using a systematic strategy. The two fundamental approaches are linear search (check every element one by one) and binary search (repeatedly halve the search space in sorted data).

💡 Intuition

Looking for a book on a shelf, a name in a list, a file on your computer.

🎯 Core Idea

The best search strategy depends on whether the data is sorted and how large the collection is.

Example

Linear search: check each item. Binary search: repeatedly halve the search space.

🌟 Why It Matters

Searching is one of the most common operations in computing. Databases, search engines, spell checkers, and file systems all depend on efficient search algorithms to find information quickly among millions or billions of items.

💭 Hint When Stuck

When choosing a search algorithm, first check whether the data is sorted. If unsorted, use linear search. If sorted, use binary search for dramatically faster performance. Always consider the size of the data—for very small collections, the choice barely matters.

Formal View

Search algorithms solve the problem: given a collection A and a target value t, find the index i such that A[i] = t, or report that t is not in A. Linear search runs in O(n); binary search in O(\log n) on sorted data.

🚧 Common Stuck Point

Binary search requires sorted data—but is much faster than linear search.

⚠️ Common Mistakes

  • Applying binary search to unsorted data, which gives incorrect results
  • Not handling the case where the target value is not found in the collection
  • Using linear search on large sorted datasets when binary search would be orders of magnitude faster

Frequently Asked Questions

What is Searching in CS Thinking?

The process of locating a specific item or value within a collection of data using a systematic strategy. The two fundamental approaches are linear search (check every element one by one) and binary search (repeatedly halve the search space in sorted data).

When do you use Searching?

When choosing a search algorithm, first check whether the data is sorted. If unsorted, use linear search. If sorted, use binary search for dramatically faster performance. Always consider the size of the data—for very small collections, the choice barely matters.

What do students usually get wrong about Searching?

Binary search requires sorted data—but is much faster than linear search.

How Searching Connects to Other Ideas

To understand searching, you should first be comfortable with array and algorithm. Once you have a solid grasp of searching, you can move on to linear search and binary search.

💻 Animated Visualization Animated

Compare linear vs binary search strategies