Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7753393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T12:03:12+00:00 2026-06-01T12:03:12+00:00

In a binary search implementation, obviously: mid = (low + high)/2 can cause overflow.

  • 0

In a binary search implementation, obviously:

mid = (low + high)/2

can cause overflow. I have read a lot of documentation (like this) that the following prevents the problem:

mid = (low + high) >>> 1 

However, I did not see a reason why this would work. Can anyone throw some light on this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T12:03:13+00:00Added an answer on June 1, 2026 at 12:03 pm

    There is no such thing as a “logical right shift” in C (there’s no >>> operator), so you’re probably talking about Java.

    This works because low and high are presumed to be in the range 0 to 2^31-1 (assuming we’re talking about int here). The maximum possible value of low+high is no greater than than 2^32-2, and so is representable by an unsigned int (if such a thing existed in Java). Such a thing doesn’t exist in Java, so we’ve now overflowed. However, the logical shift operator >>> treats its operand as if it were unsigned, so this gives the expected result.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In binary search algorithm we have two comparisons: if (key == a[mid]) then found;
I have a binary search loop which gets hit many times in the execution
I have a binary search function that will search for a word in an
i have implement binary search tree in c++ #include <iostream> #include <cstdlib> using namespace
Implementation Use: Data Structure Lab Exercise for October/28/2011 To do: Implement a Binary Search
I have a binary search function I am passing a pointer character array, the
I'm curious if anyone could explain a branchless binary search implementation to me. I
Do you know, please, if C++ STL contains a Binary Search Tree (BST) implementation,
In the implementation of binary search int search(int[] A, int K) { int l
Since black red tree is a binary search tree I have decided to use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.