Question:

Which one of the following is the Middle element index formula:

Show Hint

Standard midpoint formula is \((low + high)/2\). For overflow-safe implementations in competitive coding, write it as \(low + (high - low)/2\).
Updated On: Jun 3, 2026
  • (low + high)/2
  • low $\times$ high
  • high $-$ low
  • low/high
Show Solution
collegedunia
Verified By Collegedunia

The Correct Option is A

Solution and Explanation


Step 1: Understanding the Question:

The question asks for the correct mathematical formula used to calculate the index of the middle element in a sub-array during algorithms like binary search.

Step 2: Key Formula or Approach:

When searching an array between a lower bound index \(low\) and an upper bound index \(high\), we find the midpoint to divide the search space.

Step 3: Detailed Explanation:

$\bullet$ To find the exact midpoint of a range bounded by \(low\) and \(high\), we calculate the arithmetic mean of the two boundaries.
$\bullet$ This is represented as:
\[ mid = \frac{low + high}{2} \]
$\bullet$ In integer arithmetic, this division is typically truncated or floor-divided to produce an integer index.
$\bullet$ Let us look at why the other options are mathematically incorrect for finding a midpoint:
$\bullet$ Option (B) \(low \times high\) performs multiplication, which yields an unrelated, very large index value.
$\bullet$ Option (C) \(high - low\) computes the distance or size of the range, not the midpoint index itself.
$\bullet$ Option (D) \(low / high\) computes a ratio, which is typically close to zero and does not represent a middle index.
$\bullet$ Note: While \((low + high)/2\) is standard, in systems with large arrays, it can cause integer overflow if \(low + high\) exceeds the maximum value of a 32-bit integer. To prevent this, the formula can also be written as \(low + (high - low)/2\).

Step 4: Final Answer:

Hence, the standard formula to find the middle element index is \((low + high)/2\), which is option (A).
Was this answer helpful?
0
0