Bisect a commit history

A test that passed on commit 0 fails on commit 300. The commits are numbered 1 to 300 in order, every commit builds, the test gives the same result every time it runs on a given commit, and once a commit fails, every later commit also fails. You want the first failing commit.


You use this bisection rule. Let lo be the last commit known to pass and hi the first commit known to fail, starting with lo = 0 and hi = 300. Test commit m=⌊(lo+hi)/2⌋m = \lfloor (lo + hi)/2 \rfloor; if it passes, set lo = m, and if it fails, set hi = m. Stop when hi = lo + 1; then hi is the first failing commit.


The first four tests give: fail, pass, pass, fail.


Give each answer as a whole number:

  1. the commit number tested fifth;
  2. the number of commits still possible as the first failing commit after the four tests;
  3. the worst-case total number of tests this rule needs, counted from the start, to find the first failing commit among the original 300 candidates.
Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Debugging Strategies Questions: