Advanced Code Reading #algorithms #interviews #recursion

📐 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;
}