Skip to content
Sahithyan's S2
Sahithyan's S2 — Data Structures and Algorithms

Searching

Used to retrieve information stored within some data structure. Below is an explanation of common searching algorithms along with their time and space complexities.

Common searching algorithms

The simplest searching algorithm. It checks each element of the list sequentially until the desired element is found or the list ends.

An efficient algorithm for finding an item from a sorted list of items. Works by repeatedly dividing the search interval in half.

Depth-first search and breadth-first search are explained in their respective sections.

Comparison

AlgorithmBest TimeWorst TimeAverage TimeMemory
Linear SearchO(1)O(1)O(n)O(n)O(n)O(n)O(1)O(1)
Binary SearchO(1)O(1)O(logn)O(\log n)O(logn)O(\log n)O(1)O(1)
Depth-First Search (DFS)O(V+E)O(V + E)O(V+E)O(V + E)O(V+E)O(V + E)O(V)O(V)
Breadth-First Search (BFS)O(V+E)O(V + E)O(V+E)O(V + E)O(V+E)O(V + E)O(V)O(V)