Course: Advanced Data Structures and Algorithms
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.
Translating high-level intuition into concrete code requires defining clear variables and boundaries.
-
Search Interval: Represented by
L(Left) andR(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).
- A non-empty sub-array satisfies
-
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
-1to represent "Not Found." This is a design decision to maintain a uniform integer output type.
- The instructor provides the Recursive version of Binary Search, which calls itself with updated
LorRvalues. - 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.
-
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.
A new problem is presented: finding specific positional elements in a set
-
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.
- 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