Algorithms · Searching Algorithms
Introduction to Searching Algorithms
Overview
A search algorithm retrieves information stored within a data structure, answering whether a given element is present in that structure.
Searching is fundamental because it underlies everyday operations such as database queries and search engines, and this chapter studies two methods: linear search and binary search.
Key concepts
- Search algorithm: an algorithm that retrieves information stored within some data structure.
- Searching: for a given element, finding whether that element is present in the data structure or not.
- Data structures that can be searched: linked lists, arrays, search trees, hash tables, and various other storage methods.
- Applications of searching: the SQL
SELECTcommand (in a database, aSELECTis essentially a search for an element) and search engines (a search engine also performs a search). - Methods covered: only two search methods — linear search and binary search.
How it works
- Data is stored in some data structure (array, linked list, tree, etc.).
- The task is to determine whether a given element is present in that structure.
- The methods are studied in order: linear search first, then binary search.
Revision summary
- A search algorithm retrieves information stored within a data structure.
- Searching answers: given an element, is it present in the data structure or not?
- Data structures searched can be arrays, linked lists, search trees, hash tables, or other storage methods.
- Applications include the SQL
SELECTcommand in databases and search engines. - Only two search methods are covered: linear search and binary search; linear search is studied first.
- Searching retrieves an element (or reports its absence) from a data structure such as an array, linked list, search tree or hash table.
Previous-year exam insights
- Linear search scans elements sequentially and works on unsorted as well as sorted data; its worst-case and average-case time complexity is and best case is .
Asked inGATE 2021GATE 2022 - Binary search requires the array to be sorted (and random access, so it suits arrays but not linked lists); its worst-case time complexity is and best case .
Asked inGATE 2022GATE 2024 - For a successful binary search on n sorted elements, the number of comparisons is at most ceil() (equivalently floor()+1); the maximum number of comparisons for an unsuccessful search is ceil().
Asked inGATE 2022 - The recurrence for binary search is T(n) = T(n/2) + , giving T(n) = by the Master theorem (case 2).
Asked inGATE 2022 - Searching is the basis of graph traversals: BFS and DFS each visit every vertex and edge once, taking time with adjacency lists ( with an adjacency matrix).
Asked inGATE 2026GATE 2025GATE 2024 - BFS finds shortest paths (in edge count) in unweighted graphs, whereas DFS does not; DFS is used for topological sorting, cycle detection and finding connected components.
Asked inGATE 2025GATE 2024GATE 2021