🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Searching and Sorting in C: all 10 questions

Quiz: Searching and Sorting in C · Question 6 of 10

Why write mid = low + (high - low) / 2 instead of (low + high) / 2?

Why write mid = low + (high - low) / 2 instead of (low + high) / 2?

  1. A.It is faster
  2. B.It rounds up instead of down
  3. C.low + high can overflow an int for very large indexes; this form cannot
  4. D.It is needed for unsorted arrays
Answer & explanation

Correct answer: low + high can overflow an int for very large indexes; this form cannot

Both give the same middle, but only this form is safe when low and high are close to INT_MAX.

Can you get the rest right without peeking?

Take the timed Quiz: Searching and Sorting in C quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →