/
You know s is in the half-open-half-closed interval [lowEnough, tooHig You know s is in the half-open-half-closed interval [lowEnough, tooHig

You know s is in the half-open-half-closed interval [lowEnough, tooHig - PDF document

lindy-dunigan
lindy-dunigan . @lindy-dunigan
Follow
460 views
Uploaded On 2016-04-21

You know s is in the half-open-half-closed interval [lowEnough, tooHig - PPT Presentation

s is in the halfopenhalfclosed interval lowEnough tooHigh where the endpoints are integers ID: 287430

the half-open-half-closed

Share:

Link:

Embed:

Download Presentation from below link

Download Pdf The PPT/PDF document "You know s is in the half-open-half-clos..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Hints on Interval Halving��7 January 2019��OSU CSE The Guessing GameRules:You are trying to determinefor some ecret negative realnumber You know is in the halfintervalervallowEnoughtooHighwhere the points are integerYou may ask only one kind of question about an integer: is it true that s g�.5 ;�.5 ;7 January 2019�.5 ;�.5 ;OSU CSE The Guessing GameRules:You are trying to determinefor some secret negative realnumber You know is in the halfintervalervallowEnoughtooHighwhere the points are integerYou may ask only one kind of question about an integer: is it true that s g�.5 ;�.5 ;7 January 2019�.5 ;�.5 ;OSU CSE This notation, pronouncedfloor of s, means the greatest integer less than or equal to ; for nonnegative , it is also known as the integer part of s(Example: The Guessing GameRules:You are trying to determinefor some secret negative realnumber You know is in the halfintervalervallowEnoughtooHighwhere the points are integerYou may ask only one kind of question about an integer: is it true that s g�.5 ;�.5 ;7 January 2019�.5 ;�.5 ;OSU CSE points have meaningful names:low enough to be , too high to be Approach to the Guessing GameAs long as the interval al lowEnoughtooHighcontains more than one integer (i.e., tooHighlowEnough), repeat:Guess the floor of the midpoint of the interval as , asking whether s gDepending on the answer to this question, replace either lowEnoughtooHighwith When lowEnough, there is only one possible answer: lowEnough�.5 ;�.5 ;7 January 2019�.5 ;�.5 ;OSU CSE Approach to the Guessing GameAs long as the interval al lowEnoughtooHighcontains more than one integer (i.e., tooHighlowEnough), repeat:Guess the floor of the midpoint of the interval as , asking whether s gDepending on the answer to this question, replace either lowEnoughtooHighwith When lowEnough, there is only one possible answer: lowEnough�.5 ;�.5 ;7 January 2019�.5 ;�.5 ;OSU CSE The term interval halving for this algorithm (also called binary search) comes from the fact that each iteration eliminates half the previous interval. The RootGuessing GameRules:You are trying to determine for given nonnegative integer(and you can’t compute directly, so is just like the secret realnumberYou know is in the halfintervalervallowEnoughtooHighwhere the points are integerYou may ask only one kind of question about an integer: is it true that ��7 January 2019��OSU CSE As long as the interval al lowEnoughtooHighcontains more than one integer (i.e., tooHighlowEnough), repeat:Guess the floor of the midpoint of the interval as , asking whether Depending on the answer to this question, replace either lowEnoughtooHighwith When lowEnough, there is only one possible answer: lowEnough��7 January 2019��OSU CSE��8&#x/BBo;&#xx [-;.94; 4;E.4;ࢄ ;ݘ.;ڈ&#x 500;&#x.115; ]/;&#xSubt;&#xype ;&#x/Foo;&#xter ;&#x/Typ; /P; gin; tio;&#xn 00;&#x/BBo;&#xx [-;.94; 4;E.4;ࢄ ;ݘ.;ڈ&#x 500;&#x.115; ]/;&#xSubt;&#xype ;&#x/Foo;&#xter ;&#x/Typ; /P; gin; tio;&#xn 00;Approach to the RootGuessing Game How Can This Algorithm Work?The problem seems to be that, without already knowing the secret number you cannot directly answer the question: is it true that Observe: answering whether is the same as answering whether In other words, if you can compute , then you can guess using the same approach as you used to guess the secret number��7 January 2019��OSU CSE Example: Find What is the actual answer?Since the (i.e., square) root of is about 4.47, we have Let’s see how this can be determined by interval halvingWe need a starting interval known to contain is low enough to be the answer20 + 1 = is too high to be the answer��7 January 2019��OSU CSE Example: Find [ )Guess g = 10. Is ? Yes.So, is too high to be In other words, there is no point in ever ��7 January 2019��OSU CSE Example: Find [ )Guess g = 5. Is ? Yes.So, is too high to be In other words, there is no point in ever ��7 January 2019��OSU CSE Example: Find [ )Guess g = 2. Is ? No.So, low enough to In other words, there is no point in ever guessing lower than ��7 January 2019��OSU CSE Example: Find [ )Guess g = 3. Is ? No.So, is low enough to be In other words, there is no point in ever guessing lower than ��7 January 2019��OSU CSE Example: Find nd )&#x/MCI; 8 ;&#x/MCI; 8 ;Guess g = 4. Is ? No.So, is low enough to be In other words, there is no point in ever guessing lower than &#x/MCI; 8 ;&#x/MCI; 8 ;7 January 2019&#x/MCI; 8 ;&#x/MCI; 8 ;OSU CSE Example: Find nd )&#x/MCI; 8 ;&#x/MCI; 8 ;We now know that 4 ≤ so the answer must be ≤ ≤ 7 January 2019≤ ≤ OSU CSE