- #1
zak100
- 462
- 11
Homework Statement
Hi,
I have a problem understanding the following equation related to binary search:
Homework Equations
int midIndex = (endIndex - startIndex / 2) + startIndex;
The Attempt at a Solution
If: endIndex = 10
startIndex = 0
then midIndex = (10 - 0/2) + 0;
midIndex = (10-0) +0;
midIndex = 10;
I don't think, this is right. midIndex should be 5 as name implies.
Some body please guide, what's my error.
Zulfi.