Skip to content

Updated bsearch.cpp to avoid integer overflow#62

Open
adityaag24 wants to merge 2 commits into
akshaydmc:masterfrom
adityaag24:master
Open

Updated bsearch.cpp to avoid integer overflow#62
adityaag24 wants to merge 2 commits into
akshaydmc:masterfrom
adityaag24:master

Conversation

@adityaag24
Copy link
Copy Markdown

Change

  1. Updated bsearch.cpp to handle integer overflow
  2. Made the logic more readable by using while loop only.
    Explanation:
    When adding lower and higher, it might happen that the addition value is more than the maximum possible value of an integer. The better way to handle it is to offset the value (higher - lower)/2 to the lower value to calculate the middle point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant