Skip to content

Latest commit

 

History

History
59 lines (51 loc) · 3.78 KB

File metadata and controls

59 lines (51 loc) · 3.78 KB

Lecture 6: Binary Search Formalization & Order Statistics Intro [28/01/2026]

Course: Advanced Data Structures and Algorithms


1. Decrymental Design: Binary Search Logic [00:00:12]

The instructor reviews Binary Search as the canonical example of Decrymental Design (pruning).

  • Requirement: The array must be sorted. Searching an unsorted array requires Linear Search ($O(n)$), while a sorted array allows $O(\log n)$ efficiency.
  • Pruning: By checking the middle value, 50% of the search space is eliminated in each iteration.

2. Formalizing the Algorithm [00:10:34]

Translating high-level intuition into concrete code requires defining clear variables and boundaries.

  • Search Interval: Represented by L (Left) and R (Right).
  • Subtlety of Boundary [00:17:17]:
    • A non-empty sub-array satisfies $L \le R$, containing $R-L+1$ elements.
    • If $L > R$, the sub-array is empty (the element is not found).
  • Iteration Logic:
    • $M = \lfloor (L+R)/2 \rfloor$.
    • If $A[M] = X$: Success (Return Index).
    • If $A[M] > X$: Shrink from right ($R = M-1$).
    • If $A[M] < X$: Shrink from left ($L = M+1$).
  • Termination Convention [00:26:42]: Return -1 to represent "Not Found." This is a design decision to maintain a uniform integer output type.

3. Iterative vs. Recursive Implementation [00:36:52]

  • The instructor provides the Recursive version of Binary Search, which calls itself with updated L or R values.
  • Programming Fundamentals [00:42:33]:
    • Formal Parameters: The template variables (A, X, L, R) used in the function definition/specification.
    • Actual Parameters: The specific values (B, Y, 0, 1500) passed during the invocation or call.

4. Complexity and Data Structure Selection [00:48:09]

  • The Power of Logarithms: Dividing by 2 repeatedly reaches 1 in $\log n$ steps. For $10^6$ items, this takes only ~20 iterations.
  • Sorted Array Limitations: While great for searching ($O(\log n)$), sorted arrays are inefficient for dynamic insertions and deletions ($O(n)$ work to shift elements).
  • Red-Black Trees: Briefly introduced as a structure that handles search, insert, and delete all in $O(\log n)$ time.

5. Introduction to Order Statistics [00:54:49]

A new problem is presented: finding specific positional elements in a set $S$.

  • Definition of Rank [00:55:13]: The number of elements in the set strictly smaller than $X$.
  • Kth Smallest Element:
    • 1st Smallest = Minimum.
    • $n$th Smallest = Maximum.
    • The goal is to find the $k$th smallest element for any $k$ (e.g., the 473rd smallest in a set of 7,948).
  • Relevance: Crucial for competitive exams (percentiles, ranking).
  • Teaser [01:06:38]: There is a "stunningly amazing" $O(n)$ solution for this selection problem that uses pruning, to be discussed next class.

6. Administrative: Tech Issues & Assignments [01:07:07]

  • Class Interruptions: Technical issues (power/net) caused some frustration.
  • Assignment Access: Several students (August 2025 and new batches) reported missing SML accounts and Google Drive access.
  • Action Plan: The instructor will personally contact admin (Ravi Chandran) to ensure all students have proper IDs and Drive access.
  • Deadline Extension: Because of these technical delays, the first assignment deadline is extended by an extra week.
  • OneNote Difficulty: The instructor mentions that the current iPad version of OneNote has made it difficult to export/mail lecture notes, contributing to the delay in posting PDFs.

Key Terms Corrected:

  • decriminal design -> Decrymental Design
  • formal parameters -> Formal Parameters
  • actual parameters -> Actual Parameters
  • order statistics -> Order Statistics
  • rank -> Rank
  • kth smallest -> Kth Smallest Element