Home/Notes/Sorting & Searching
Board Exam Notes

Sorting & Searching Notes

Questions

3 questions per exam

Difficulty

Medium

Importance

High yield for University Semester exams and placement coding rounds

Overview

Sorting and searching are fundamental algorithmic techniques used to organize and retrieve data efficiently within a computer system. Mastering these is critical for exams, as they form the foundation of computational complexity analysis and are frequently tested through both theoretical questions and trace-based numerical problems.

Comparison-Based Sorting Algorithms

These algorithms sort data by comparing elements using comparison operators. Understanding their time complexity across best, average, and worst cases is essential for writing efficient code and answering analytical exam questions.

  • Bubble Sort: O(n^2) worst case, stable sort.
  • Selection Sort: O(n^2) performance, minimal swaps.
  • Insertion Sort: O(n) best case, ideal for small/nearly sorted data.
  • Merge Sort: O(n log n) divide and conquer strategy.
  • Quick Sort: O(n log n) average case, pivot-based partitioning.

Searching Techniques

Searching is the process of finding an element in a collection. You must be able to distinguish between linear search for unsorted lists and binary search for sorted lists.

  • Linear Search: O(n) complexity, works on unordered lists.
  • Binary Search: O(log n) complexity, requires sorted arrays.
  • Binary Search Condition: Array must be sorted or partitioned.
  • Midpoint Formula: mid = low + (high - low) / 2 to avoid overflow.

Time Complexity and Comparative Analysis

Comparing the efficiency of algorithms through Big-O notation is a standard examination requirement. You should be prepared to derive these complexities and justify why certain algorithms outperform others in specific memory or speed constraints.

  • Omega (Ω) notation: Best case lower bound.
  • Theta (Θ) notation: Average case tight bound.
  • Big-O (O) notation: Worst case upper bound.
  • Space Complexity: Merge Sort requires O(n) extra space.
  • In-place sorting: Selection and Bubble sort.

Formula Sheet

Binary Search Mid: mid = low + (high - low) / 2

Master Theorem for recurrence relations: T(n) = aT(n/b) + f(n)

Exam Tip

Always draw the recursive tree or trace the array swaps step-by-step for sorting questions to ensure partial credit even if the final calculation has an error.

Common Mistakes

  • Confusing the best and worst-case time complexities of Quick Sort and Merge Sort.
  • Forgetting that Binary Search requires the input array to be pre-sorted.
  • Miscalculating the mid-point index in Binary Search due to integer overflow.

More Revision Notes

Ready to test yourself?

Play topic-wise Sorting & Searching questions in Aspirant Arcade — gamified MCQ practice.

Download Free