Q:

In the binary search program on page 112, why did we write mid = beg + (end - beg) / 2; instead of mid = (beg + end) /2;

0

In the binary search program on page 112, why did we write mid = beg + (end - beg) / 2; instead of mid = (beg + end) /2;?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

First, there is no operator `+` for two iterators.

Second, for arithmetic types, using `mid = (beg + end) / 2` may lead to overflow.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now