RTUComputer ScienceYr 2023 · Sem 52023

Q2Design and Analysis of Algorithms

Question

4 marks

Describe the Binary Search algorithm and analyze its time complexity.

Answer

A technical deconstruction of the Binary Search algorithm, utilizing the Divide and Conquer paradigm on strictly sorted arrays, followed by a rigorous logarithmic time complexity analysis.

Binary Search is a highly advanced, fiercely optimized search algorithm that fundamentally utilizes the Divide and Conquer architectural paradigm. Unlike primitive linear searches that mindlessly scan every element, Binary Search mathematically exploits a strict physical pre-condition: the target array must be absolutely and perfectly sorted in ascending or descending order. By leveraging this sorted state, it aggressively halves the searchable data space during every single CPU iteration.

The Algorithmic Execution

The algorithm strictly maintains two physical pointers: Low (initial index 0) and High (initial index ).

  • 1. Midpoint Calculation: It mathematically calculates the absolute center index of the current active search space: Mid = (Low + High) / 2 (utilizing integer floor division).
  • 2. The Triage: It aggressively compares the Target Value against the element physically residing at Array[Mid].
  • 3. The Halving Phase: - If Target == Array[Mid], the search instantly terminates with total success. - If Target < Array[Mid], the mathematical logic dictates the target must physically reside in the left half. It violently discards the entire right half by updating High = Mid - 1. - If Target > Array[Mid], it violently discards the entire left half by updating Low = Mid + 1.
  • 4. Recursion/Loop: The algorithm ruthlessly repeats this sequence until the Target is located or the Low pointer mathematically crosses the High pointer (indicating absolute failure).

Rigorous Time Complexity Analysis

To calculate the absolute Worst-Case Time Complexity , we must analyze the mathematical rate of array destruction. In the worst-case scenario (the element is missing), the array of size is continuously divided by 2.

  • Iteration 1: Array size is
  • Iteration 2: Array size is
  • Iteration 3: Array size is
  • Iteration : Array size is

The algorithm halts precisely when the array size collapses to exactly 1 element. Therefore, we set the equation: .

Mathematically solving for (the total number of iterations): .

Thus, the absolute worst-case time complexity is rigidly proven to be , making it exponentially superior to linear searches for massive databases.

Back to Paper