different search techniques

Comprehensive study notes, diagrams, and exam preparation for different search techniques.

Different Search Techniques

Definition

A search technique is a method or algorithm used to locate a specific element, value, record, or state within a collection of data or a problem space.

In computer science, a search technique aims to determine:

  • whether the required item exists,
  • where it is located,
  • and how efficiently it can be found.

Search techniques may be:

Linear

  • , where items are checked one by one,

Binary or ordered

  • , where the search space is repeatedly divided,

Tree-based or graph-based

  • , where structures are traversed,

Heuristic

  • , where informed guesses guide the search.

Example:
If a student number is to be found in a list of 1,000 records:

  • a linear search checks each record one by one,
  • a binary search can find it much faster if the list is sorted.

Main Content

1. Linear Search

Meaning and method

  • Linear search, also called sequential search, is the simplest search technique. It starts from the first element and compares each item with the target until the item is found or the list ends.

How it works in practice

  • Suppose a list is [45, 12, 78, 30, 99] and the target is 30. Linear search checks 45, then 12, then 78, and finally 30, where it stops.

Advantages

  • It can be used on both sorted and unsorted data. It is easy to understand, easy to implement, and requires no special arrangement of data.

Limitations

  • It becomes slow when the list is very large because, in the worst case, every element may need to be checked.

Best use cases

  • Small datasets, unsorted lists, or situations where data changes frequently and sorting is not practical.

Example:
Searching for a roll number in an unsorted attendance list.

Time complexity:

  • Best case: O(1) if the item is first
  • Worst case: O(n) if the item is last or absent

2. Binary Search

Meaning and method

  • Binary search is a fast search technique used only on sorted data. It works by repeatedly dividing the search interval into two halves.

How it works

  • First, the middle element is checked. If the target is smaller, the search continues in the left half; if larger, it continues in the right half. This process repeats until the target is found or the search range becomes empty.

Advantages

  • It is much faster than linear search for large sorted datasets because each step removes half of the remaining elements.

Limitations

  • The data must already be sorted. If data changes often, maintaining sorting may take extra time.

Best use cases

  • Dictionaries, sorted arrays, student marks arranged in order, database indexes, and lookup tables.

Example:
Searching for 23 in [5, 9, 12, 16, 23, 27, 31]:

  • middle = 16
  • 23 > 16, so search right half
  • middle of right half = 27
  • 23 < 27, so search left part
  • target 23 is found

Time complexity:

  • Best case: O(1)
  • Worst case: O(log n)

Visual idea for process:

[ 5 | 9 | 12 | 16 | 23 | 27 | 31 ]
              ^
           middle
If target > middle → search right half
If target < middle → search left half

3. Tree and Graph Search

Meaning and method

  • Tree and graph search techniques are used when data is organized in hierarchical or network form rather than a simple list. These techniques are common in data structures, databases, AI, and routing systems.

Main types

  • Depth-First Search (DFS): Goes as deep as possible along one path before backtracking.
  • Breadth-First Search (BFS): Explores all nodes level by level before moving deeper.

Advantages

  • These methods are useful for exploring complex relationships, finding paths, checking connectivity, traversing trees, and solving puzzles.

Limitations

  • They may consume more memory or time depending on graph size, structure, and whether cycles exist.

Best use cases

  • Tree traversal, shortest path in unweighted graphs, web crawling, social network analysis, AI state-space search, and routing.

Example of DFS:
In a tree, DFS may visit nodes in the order: A → B → D → E → C

Example of BFS:
BFS may visit nodes level by level: A → B → C → D → E

Diagram for tree traversal:

        A
      /   \
     B     C
    / \
   D   E
  • DFS might go: A → B → D → E → C
  • BFS might go: A → B → C → D → E

Time complexity:

  • BFS: O(V + E) for graphs
  • DFS: O(V + E) for graphs
    where V = vertices and E = edges

Working / Process

1. Identify the nature of the data or problem

  • Check whether the data is sorted, unsorted, hierarchical, or network-based.
  • Example: If a list is unsorted, binary search cannot be used directly.

2. Choose the appropriate search technique

  • Use linear search for small or unsorted datasets.
  • Use binary search for sorted datasets.
  • Use BFS or DFS for trees, graphs, and structured exploration problems.

3. Execute the search and compare results

  • Compare the target with elements or nodes according to the selected method.
  • Continue until the item is found or the search space becomes empty.
  • Confirm the output and, if needed, record the position, path, or node where the target was located.

Simple process flow:

Start → Check data type → Select search method → Compare/search → Found?
                                            ↙ Yes      ↘ No
                                      Return result   Report not found

Advantages / Applications

Saves time and effort

  • Efficient search techniques reduce the number of comparisons needed to find an item.

Useful in real-world systems

  • Search is used in file systems, search engines, databases, libraries, navigation systems, and AI applications.

Improves problem-solving efficiency

  • Choosing the correct search method helps solve tasks faster and more accurately.

Applications in practice:

  • Finding a name in a list of students
  • Looking up a word in a dictionary
  • Searching records in a database
  • Traversing trees in programming
  • Finding routes in maps and networks
  • Retrieving web pages using search engines
  • Solving AI problems like maze navigation or game moves

Summary

  • Search techniques are methods used to locate a required item or solution.
  • Linear search checks elements one by one, while binary search works on sorted data by dividing the search space.
  • Tree and graph search techniques are used for structured and network-based problems.

Important terms to remember

  • search technique, linear search, binary search, DFS, BFS, sorted data, traversal