1. Gyanastra
  2. Algorithms
  3. Searching Algorithms
  4. Introduction to Searching Algorithms
Free lesson, no account needed 3 min read 14 practice questions after it
Asked in past papers12 times
  • GATE CSE20262025202420232022202120182017201420082005
  • ISRO2011

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 SELECT command (in a database, a SELECT is 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

  1. Data is stored in some data structure (array, linked list, tree, etc.).
  2. The task is to determine whether a given element is present in that structure.
  3. 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 SELECT command 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 O(n)O(n) and best case is O(1)O(1).
    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 O(log⁡n)O(\log n) and best case O(1)O(1).
    Asked inGATE 2022GATE 2024
  • For a successful binary search on n sorted elements, the number of comparisons is at most ceil(log⁡2(n+1)\log_{2}(n+1)) (equivalently floor(log⁡2n\log_{2} n)+1); the maximum number of comparisons for an unsuccessful search is ceil(log⁡2(n+1)\log_{2}(n+1)).
    Asked inGATE 2022
  • The recurrence for binary search is T(n) = T(n/2) + O(1)O(1), giving T(n) = O(log⁡n)O(\log 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 O(V+E)O(V+E) time with adjacency lists (O(V2)O(V^{2}) 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
Pages 1–2 of 2