📐 Describing Algorithms
3 exercises — read algorithm implementations and describe the logic in plain English. Essential for technical interviews and pair programming.
0 / 3 completed
Describing algorithms — sequence language
- "First, it checks / initialises / sorts…"
- "On each iteration / pass, it compares…"
- "If the condition is met, it returns / swaps / continues…"
- "The base case is when… / The recursive case is…"
- "This runs in O(n log n) time because…"
1 / 3
Read this binary search implementation. Which description uses the most natural and accurate English?
function binarySearch(arr, target) {
let left = 0, right = arr.length - 1;
while (left <= right) {
const mid = Math.floor((left + right) / 2);
if (arr[mid] === target) return mid;
if (arr[mid] < target) left = mid + 1;
else right = mid - 1;
}
return -1;
}Option B is the most complete and natural explanation. It: (1) names the algorithm and its key requirement (sorted array), (2) describes the search process step-by-step in plain English using sequence words ("starts by", "if it matches"), (3) covers all three paths: found, search right, search left, and (4) states the return value on failure. Option A only describes the implementation structure without explaining the logic. Option C is partially good but skips the "why" of adjusting boundaries. Option D is technically accurate but speaking complexity class alone (O(log n)) doesn't describe how the algorithm works. For algorithm descriptions in English, always describe the input requirement, the core loop logic, and what the output means.