A search algorithm is any systematic method for locating a target element, value, path, or pattern within a collection, structure, or abstract space. The term covers simple procedures that examine items one by one and sophisticated methods that exploit order, indexing, hashing, or domain knowledge to avoid inspecting every element. Search algorithms are fundamental in computer science and appear across databases, information retrieval, graph theory, artificial intelligence, and everyday software.
Basic categories and examples
Common categories include:
- Linear search: inspects each element in sequence; simple and requires no extra structure but is O(n) in time for n items.
- Binary and other divide-and-conquer searches: operate on sorted collections and reduce the remaining search space rapidly (logarithmic behaviour when random access is available).
- Hash-based lookup: uses a hash function to map keys to buckets, often giving average constant-time lookup in practice; see hash tables.
- Tree and index searches: range queries and ordered lookup on balanced trees or database indexes.
Search in graphs and AI
When the domain is a network of nodes and edges, search finds paths or reachable states. Breadth-first search (BFS) and depth-first search (DFS) are standard for unweighted graphs; Dijkstra's algorithm and A* extend these ideas to weighted or heuristic-guided searches. In artificial intelligence and planning, heuristic and approximate searches trade completeness for speed, enabling solutions in very large or continuous spaces.
Performance, trade-offs and requirements
Different techniques assume different preconditions: sorted data, random access, or available memory for auxiliary structures. Key trade-offs include time versus space (indexes and caches speed queries at the cost of memory), preprocessing time versus query time (building an index or hash table speeds later lookups), and average-case versus worst-case guarantees. Many search methods are analyzed using Big-O notation to express how cost grows with input size.
Applications and notable facts
Search algorithms power database queries, web search, spell checking, routing, genome sequence matching, and real-time path planning in robotics and games. They differ from sorting algorithms, though the two often interact: sorted data enables faster comparison-based searches. Practical implementations must also consider concurrency, distribution, and fault tolerance in large-scale systems.
Understanding the structure of the data and the expected query patterns is essential when choosing a search method: a simple linear scan may suffice for tiny collections, while large-scale systems usually rely on indexing, hashing, or specialized graph search strategies to achieve acceptable performance.


