Unit 9: Searching  (DSA)– Exam Revision Notes

1. Introduction to Searching

  • Searching = Process of finding the location of a specific element in a data structure.
  • Essential for data retrieval, processing, and algorithm efficiency.
  • Key Concepts:
    1. Search key – The element we want to find.
    2. Search space – The dataset where the search is performed.
    3. Efficiency – Measured by time complexity and number of comparisons.

2. Types of Searching Techniques

1. Sequential (Linear) Search

  • Scan elements one by one from start to end.
  • Time Complexity: O(n).
  • Advantages: Simple, works on unsorted data.
  • Disadvantages: Inefficient for large datasets.

2. Binary Search

  • Works on sorted arrays only.
  • Divide the array, compare middle element with key, reduce search space by half each time.
  • Time Complexity: O(log n).
  • Advantages: Fast for large sorted data.
  • Disadvantages: Requires sorted data, not suitable for linked lists.

3. Tree Search

  • Search in binary search trees (BST).
  • Compare key with root, recursively move to left/right subtree.
  • Time Complexity: O(h), where h = height of tree.

4. Hashing

  • Direct access using hash function.
  • Hash Table: Stores key-value pairs.
  • Hash Function: Converts key → index in table.
  • Collision Resolution Techniques:
    1. Chaining – Linked list at each index.
    2. Open Addressing – Linear probing, quadratic probing, double hashing.
  • Advantages: Fast access (O(1) on average).
  • Disadvantages: Collisions, extra memory for chains.

3. Efficiency Comparisons

Search MethodBest CaseAverage CaseWorst CaseNotes
SequentialO(1)O(n/2)O(n)Works on unsorted data
BinaryO(1)O(log n)O(log n)Sorted array required
BSTO(1)O(log n)O(n)Depends on tree balance
HashingO(1)O(1)O(n)Fastest, collisions possible

4. Key Concepts

  • Search Key = Element to find.
  • Collision = Two keys mapped to same index in hash table.
  • Load Factor = Number of elements / Table size; affects hash efficiency.
  • Balanced BST → Ensures O(log n) search.

5. Applications of Searching

  1. Database Queries – Locate records quickly.
  2. Dictionary Lookup – Spell check, auto-suggestions.
  3. Symbol Table in Compiler – Retrieve variable/function info.
  4. Network Routing – Fast packet lookup.
  5. Memory Management – Allocate/deallocate blocks efficiently.

Key Takeaways – Unit 9

  • Searching = locating specific data efficiently.
  • Linear search → simple, unsorted data.
  • Binary search → fast, sorted data.
  • Tree search → hierarchical structure, efficiency depends on balance.
  • Hashing → fastest average access, requires handling collisions.
  • Choosing search technique depends on data size, structure, and sorting.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.