Question: How to determine the right formula for calculating the middle point?

When doing binary search related problems, I'm always confused by two different ways of computing the mid pointer.

The first one is int mid = (i + j) / 2 and the second one is int mid = i + (j - i) / 2.

What's the difference and how do I pick the right one to use?

Comments (1)