@Sanjay: suppose Max_INT range is 300

now suppose

end=300 and start =2

now using (start+end)/2 i.e *302*/2 but 302 goes out of range for and
interger type as assumed...

but if we use  start + (end-start)/2 THEN  2 + (300-2)/2  , i.e 2+ *298*/2
here 298 < 300 hence it within int_Max range which was assumed 300..



On Sun, Jan 8, 2012 at 4:41 PM, Sanjay Rajpal <sanjay.raj...@live.in> wrote:

> actually book pages are images.
>
> My question is why second statement may result in overflow ?
> *
>
> Sanjay Kumar
> B.Tech Final Year
> Department of Computer Engineering
> National Institute of Technology Kurukshetra
> Kurukshetra - 136119
> Haryana, India
> Contact: +91-8053566286, +91-9729683720
> *
>
>
>
> On Sun, Jan 8, 2012 at 3:07 AM, saurabh singh <saurab...@gmail.com> wrote:
>
>>  not clear what you are trying to ask...can you quote exactly from the
>> book?
>> Saurabh Singh
>> B.Tech (Computer Science)
>> MNNIT
>> blog:geekinessthecoolway.blogspot.com
>>
>>
>>
>> On Sun, Jan 8, 2012 at 4:34 PM, Sanjay Rajpal <srn...@gmail.com> wrote:
>>
>>> In binary search,
>>>
>>> mid = start + (end-start)/2 is used to avoid overflow, as said by a book.
>>>
>>> why can't we use mid = (start + end)/2, it says this statement may
>>> result in overflow ?
>>> *
>>> Sanjay Kumar
>>> B.Tech Final Year
>>> Department of Computer Engineering
>>> National Institute of Technology Kurukshetra
>>> Kurukshetra - 136119
>>> Haryana, India
>>> Contact: +91-8053566286
>>> *
>>>
>>>  --
>>> You received this message because you are subscribed to the Google
>>> Groups "Algorithm Geeks" group.
>>> To post to this group, send email to algogeeks@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> algogeeks+unsubscr...@googlegroups.com.
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>>  --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to algogeeks@googlegroups.com.
>> To unsubscribe from this group, send email to
>> algogeeks+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to algogeeks@googlegroups.com.
> To unsubscribe from this group, send email to
> algogeeks+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to