Sie sind auf Seite 1von 3

TheMaximumGapProblem:AnAlgorithmic

ApplicationofthePigeonholePrinciple

Godfried Toussaint

TheMaximumGapProblem:AnAlgorithmic
ApplicationofthePigeonholePrinciple
Alineartimealgorithmforcomputingthemaximumgapallowingthe
constanttimecomputationof<loorfunctionsinthemodelof
computation.
GivenasetSofn>2realnumbersx1,x2,,xn.
1. Findthemaximum,xmaxandtheminimum,xmininS.
2. Dividetheinterval[xmin,xmax]into(n1)"buckets"ofequalsize
=(xmaxxmin)/(n1).
3. Foreachoftheremainingn2numbersdetermineinwhichbucket
itfallsusingthe<loorfunction.Thenumberxibelongstothekth
bucketBkif,andonlyif,(xixmin)/=k1.
4. ForeachbucketBkcomputexkminandxkmaxamongthenumbers
thatfallinBk.Ifthebucketisemptyreturnnothing.Ifthebucket
containsonlyonenumberreturnthatnumberasbothxkminand
xkmax.

TheMaximumGapProblem:AnAlgorithmic
ApplicationofthePigeonholePrinciple
5. ConstructalistLofalltheorderedminimaandmaxima:
L:(x1min,x1max),(x2min,x2max),,(x(n1)min,x(n1)max),
Note:Sincetherearen1bucketsandonlyn2numbers,bythe
PigeonholePrinciple,atleastonebucketmustbeempty.Thereforethe
maximumdistancebetweenapairofconsecutivepointsmustbeat
leastthelengthofthebucket.Thereforethesolutionisnotfound
amongapairofpointsthatarecontainedinthesamebucket.
6. InL<indthemaximumdistancebetweenapairofconsecutive
minimumandmaximum(ximax,xjmin),wherej>i.
7. Exitwiththisnumberasthemaximumgap.

Das könnte Ihnen auch gefallen