﻿
B
1
0.5
0.5
B
2
0.5
0.5
...
B
N/4
0.5
0.5
B
N/4+1
2/N
2/N
2/N
...
2/N
2/N
2/N
Figure10.22 Optimalpackingfor0.5,2/N,0.5,2/N,0.5,2/N,...
B
1
0.5
2/N
empty
B
2
0.5
2/N
empty
...
B
N/2
0.5
2/N
empty
Figure10.23 Nextﬁtpackingfor0.5,2/N,0.5,2/N,0.5,2/N,...
B
1
0.2
0.5
0.1
empty
B
2
0.4
0.3
empty
B
3
0.7
empty
B
4
0.8
empty
Figure10.24 Firstﬁtfor0.2,0.5,0.4,0.7,0.1,0.3,0.8
Convert pdf into powerpoint online - C# Create PDF from PowerPoint Library to convert pptx, ppt to PDF in C#.net, ASP.NET MVC, WinForms, WPF
Online C# Tutorial for Creating PDF from Microsoft PowerPoint Presentation
how to convert pdf to ppt online; convert pdf file to powerpoint
Convert pdf into powerpoint online - VB.NET Create PDF from PowerPoint Library to convert pptx, ppt to PDF in vb.net, ASP.NET MVC, WinForms, WPF
VB.NET Tutorial for Export PDF file from Microsoft Office PowerPoint
how to convert pdf to ppt for; how to convert pdf to powerpoint slides
10.1 GreedyAlgorithms
463
Asimplemethodofimplementingﬁrstﬁtwouldprocesseachitembyscanningdown
thelistofbinssequentially.ThiswouldtakeO(N
2
).Itispossibletoimplementﬁrstﬁtto
runinO(NlogN);weleavethisasanexercise.
Amoment’sthoughtwillconvinceyouthatatanypoint,atmostonebincanbemore
thanhalfempty,sinceifasecondbinwerealsohalfempty,itscontentswouldﬁtintothe
ﬁrstbin.Thus,wecanimmediatelyconcludethatﬁrstﬁtguaranteesasolutionwithat
mosttwicetheoptimalnumberofbins.
bounddoesnotapplyforﬁrstﬁt.Thus,onemightwonderifabetterboundcanbeproven.
Theorem10.3
LetMbetheoptimalnumberofbinsrequiredtopackalistIofitems.Thenﬁrstﬁt
neverusesmorethan
17
10
M+
7
10
bins.Thereexistsequencessuchthatﬁrstﬁtuses
17
10
(M−1)bins.
Proof
Seethereferencesattheendofthechapter.
Anexamplewhereﬁrstﬁtdoesalmostaspoorlyastheprevioustheoremwouldindi-
cateisshowninFigure10.25.Theinputconsistsof6Mitemsofsize
1
7
+,followedby
6Mitemsofsize
1
3
+,followedby6Mitemsofsize
1
2
+.Onesimplepackingplacesone
itemofeachsizeinabinandrequires6Mbins.Firstﬁtrequires10Mbins.
When ﬁrst ﬁtisrun on alargenumber of items with sizes uniformly distributed
between0and1,empiricalresultsshowthatﬁrstﬁtusesroughly2percentmorebins
thanoptimal.Inmanycases,thisisquiteacceptable.
BestFit
ﬁrstspotthatisfound,itisplacedinthetightestspotamongallbins.Atypicalpackingis
showninFigure10.26.
B
1
B
M
1/+ ε
1/+ ε
1/+ ε
1/+ ε
1/+ ε
1/+ ε
empty
...
B
M+1
B
4M
1/+ ε
1/+ ε
empty
...
B
4M+1
B
10M
1/+ ε
empty
Online Convert PowerPoint to PDF file. Best free online export
Convert a PPTX/PPT File to PDF. Just upload your file by clicking on the blue button or drag-and-drop your pptx or ppt file into the drop area.
adding pdf to powerpoint; convert pdf to ppt online without email
RasterEdge XDoc.PowerPoint for .NET - SDK for PowerPoint Document
Convert PowerPoint to ODP/ ODP to PowerPoint. Insert Pages into PowerPoint File. Download Free Trial Download and try PDF for .NET with online support.
picture from pdf to powerpoint; convert pdf file to powerpoint presentation
464
Chapter10 AlgorithmDesignTechniques
B
1
0.2
0.5
0.1
empty
B
2
0.4
empty
B
3
0.7
0.3
B
4
0.8
empty
Figure10.26 Bestﬁtfor0.2,0.5,0.4,0.7,0.1,0.3,0.8
Noticethattheitemofsize0.3isplacedinB
3
2
.
Onemightexpectthatsincewearenow makingamoreeducatedchoiceofbins,the
areinputsforwhichit(nearly)achievesthisbound.Nevertheless,bestﬁtisalsosimple
tocode,especiallyifanO(NlogN)algorithmisrequired,anditdoesperformbetterfor
randominputs.
OfﬂineAlgorithms
expecttodobetter.Indeed,sincewecaneventuallyﬁndtheoptimalpackingbyexhaustive
Themajorproblemwithalltheonlinealgorithmsisthatitishardtopackthelarge
items,especiallywhen they occurlatein theinput.Thenaturalway aroundthisisto
sorttheitems,placingthelargestitemsﬁrst.Wecanthenapplyﬁrstﬁtorbestﬁt,yield-
ingthealgorithmsﬁrstﬁtdecreasingandbestﬁtdecreasing,respectively.Figure10.27
B
1
0.8
0.2
B
2
0.7
0.3
B
3
0.5
0.4
0.1
Figure10.27 Firstﬁtfor0.8,0.7,0.5,0.4,0.3,0.2,0.1
C# PDF insert text Library: insert text into PDF content in C#.net
Able to add a single text character and text string to PDF files using online source codes in C#.NET class value, The char wil be added into PDF page, 0
convert pdf pages to powerpoint slides; convert pdf file to ppt online
XDoc.HTML5 Viewer for .NET, Zero Footprint AJAX Document Image
View, Convert, Edit, Sign Documents and Images. viewer library can be easily integrated into your ASP powerful & profession imaging controls, PDF document, image
change pdf to powerpoint; how to change pdf to powerpoint slides
10.1 GreedyAlgorithms
465
showsthatin ourcasethisyieldsanoptimalsolution (although,ofcourse,thisisnot
trueingeneral).
Inthissection,wewilldealwithﬁrstﬁtdecreasing.Theresultsforbestﬁtdecreas-
ingarealmostidentical.Since it is possiblethat theitemsizesare not distinct,some
authors prefertocallthe algorithmﬁrst ﬁtnonincreasing. Wewill stay with theorigi-
sorted.
anoptimalpackingusesMbins,thenﬁrstﬁtdecreasingneverusesmorethan(4M+1)/3
bins.
Theresultdependsontwoobservations.First,alltheitemswithweightlargerthan
1
3
willbeplacedintheﬁrstMbins.Thisimpliesthatalltheitemsintheextrabinshave
weightatmost
1
3
.Thesecondobservationisthatthenumberofitemsintheextrabinscan
beatmostM−1.Combiningthesetworesults,weﬁndthatatmost(M−1)/3extra
binscanberequired.Wenowprovethesetwoobservations.
Lemma10.1
LettheNitemshave(sortedindecreasingorder)inputsizess
1
,s
2
,...,s
N
,respectively,
andsupposethattheoptimalpackingisMbins.Thenallitemsthatﬁrstﬁtdecreasing
placesinextrabinshavesizeatmost
1
3
.
Proof
SupposetheithitemistheﬁrstplacedinbinM+1.Weneedtoshowthats
i
1
3
.We
i
>
1
3
.
Itfollowsthats
1
,s
2
,...,s
i−1
>
1
3
,sincethesizesarearrangedinsortedorder.
FromthisitfollowsthatallbinsB
1
,B
2
,...,B
M
haveatmosttwoitemseach.
Considerthestateofthesystemafterthe(i−1)stitemisplacedinabin,butbefore
theithitemisplaced.Wenowwanttoshowthat(undertheassumptionthats
i
>
1
3
)
theﬁrstMbinsarearrangedasfollows:First,therearesomebinswithexactlyone
element,andthentheremainingbinshavetwoelements.
Supposethereweretwobins,B
x
andB
y
,suchthat1 ≤x<M,B
x
hastwo
items,andB
y
hasoneitem.Letx
1
andx
2
bethetwoitemsinB
x
,andlety
1
betheitem
inB
y
.x
1
y
1
,sincex
1
wasplacedintheearlierbin.x
2
≥ s
i
,bysimilarreasoning.
Thus,x
1
+x
2
y
1
+s
i
.Thisimpliesthats
i
couldbeplacedinB
y
.Byourassumption
thisisnotpossible.Thus,ifs
i
>
1
3
,then,atthetimethatwetrytoprocesss
i
,theﬁrst
MbinsarearrangedsuchthattheﬁrstjhaveoneelementandthenextMjhavetwo
elements.
ToprovethelemmawewillshowthatthereisnowaytoplacealltheitemsinM
Clearly,notwoitemss
1
,s
2
,...,s
j
canbeplacedinonebin,byanyalgorithm,since
iftheycould,ﬁrstﬁtwouldhavedonesotoo.Wealsoknowthatﬁrstﬁthasnotplaced
anyoftheitemsofsizes
j+1
,s
j+2
,...,s
i
intotheﬁrstjbins,sononeofthemﬁt.Thus,in
anypacking,speciﬁcallytheoptimalpacking,theremustbejbinsthatdonotcontain
theseitems.Itfollowsthattheitemsofsizes
j+1
,s
j+2
,...,s
i−1
mustbecontainedin
C# PDF Convert to Tiff SDK: Convert PDF to tiff images in C#.net
with specified zoom value and save it into stream The magnification of the original PDF page size Description: Convert to DOCX/TIFF with specified resolution and
change pdf to powerpoint online; convert pdf to powerpoint online for
C# PDF File Split Library: Split, seperate PDF into multiple files
SharePoint. C#.NET control for splitting PDF file into two or multiple files online. Support to break a large PDF file into smaller files.
pdf to powerpoint slide; how to change pdf file to powerpoint
466
Chapter10 AlgorithmDesignTechniques
somesetofMjbins,andfrompreviousconsiderations,thetotalnumberofsuch
itemsis2(Mj).
1
Theproofiscompletedbynotingthatifs
i
>
1
3
,thereisnowayfors
i
tobeplaced
inoneoftheseMbins.Clearly,itcannotgoinoneofthejbins,sinceifitcould,then
ﬁrstﬁtwouldhavedonesotoo.ToplaceitinoneoftheremainingMjbinsrequires
distributing2(Mj)+1itemsintotheMjbins.Thus,somebinwouldhavetohave
threeitems,eachofwhichislargerthan
1
3
,aclearimpossibility.
assumptionmustbeincorrect.Thus,s
i
1
3
.
Lemma10.2
ThenumberofobjectsplacedinextrabinsisatmostM−1.
Proof
AssumethatthereareatleastMobjectsplacedinextrabins.Weknowthat
N
i=1
s
i
M,sincealltheobjectsﬁtinMbins.SupposethatB
j
isﬁlledwithW
j
totalweightfor
1 ≤≤ M.SupposetheﬁrstMextraobjectshavesizesx
1
,x
2
,...,x
M
.Then,since
theitemsintheﬁrstMbinsplustheﬁrstMextraitemsareasubsetofalltheitems,it
followsthat
N
i=1
s
i
M
j=1
W
j
+
M
j=1
x
j
M
j=1
(W
j
+x
j
)
NowW
j
+x
j
>1,sinceotherwisetheitemcorrespondingtox
j
wouldhavebeenplaced
inB
j
.Thus
N
i=1
s
i
>
M
j=1
1>M
ButthisisimpossibleiftheNitemscanbepackedinMbins.Thus,therecanbeat
mostM−1extraitems.
Theorem10.4
LetMbetheoptimalnumberofbinsrequiredtopackalistIofitems.Thenﬁrstﬁt
decreasingneverusesmorethan(4M+1)/3bins.
Proof
ThereareatmostM−1extraitems,ofsizeatmost
1
3
.Thus,therecanbeatmost
(M−1)/3extrabins.Thetotalnumberofbinsusedbyﬁrstﬁtdecreasingisthusat
most(4M−1)/3≤(4M+1)/3.
Itispossibletoproveamuchtighterboundforbothﬁrstﬁtdecreasingandnextﬁt
decreasing.
1
RecallthatﬁrstﬁtpackedtheseelementsintoMjbinsandplacedtwoitemsineachbin.Thus,thereare
2(Mj)items.
VB.NET PDF File Split Library: Split, seperate PDF into multiple
Split PDF file into two or multiple files in ASP.NET webpage online. Support to break a large PDF file into smaller files in .NET WinForms.
how to convert pdf to powerpoint; how to convert pdf to ppt
C# PDF Page Insert Library: insert pages into PDF file in C#.net
from the ability to inserting a new PDF page into existing PDF or pages from various file formats, such as PDF, Tiff, Word, Excel, PowerPoint, Bmp, Jpeg
conversion of pdf to ppt online; convert pdf into powerpoint
10.2 DivideandConquer
467
B
1
B
6k
+
4
B
6k
+
5
9k
+
6
B
B
6k
+
5
8k
+
5
B
B
8k
+
7
11k
+
7
B
11k
+
8
B
8k
+
6
B
Optimal
First Fit Decreasing
1/4 − 2ε
1/4 − 2ε
1/4 − 2ε
1/4 − 2ε
empty
1/4 − 2ε
1/4 + ε
1/4 − 2ε
1/4 − 2ε
1/4 − 2ε
1/2 + ε
1/4 + ε
1/4 − 2ε
1/4 + ε
1/4 + ε
1/4 + ε
empty
B
1
B
6k
+
4
1/2 + ε
1/4 + 2ε
empty
1/4 + 2ε
1/4 + 2ε
1/4 − 2ε
1/4 − 2ε
Figure10.28 Examplewhereﬁrstﬁtdecreasinguses11k+8bins,butonly9k+6bins
arerequired
Theorem10.5
LetMbetheoptimalnumberofbinsrequiredtopackalistIofitems.Thenﬁrstﬁt
decreasingneverusesmorethan
11
9
M+
6
9
bins.Thereexistsequencessuchthatﬁrst
ﬁtdecreasinguses
11
9
M+
6
9
bins.
Proof
Theupperboundrequiresaverycomplicatedanalysis.Thelowerboundisexhibited
byasequenceconsistingof6k+4elementsofsize
1
2
+,followedby6k+4elements
ofsize
1
4
+2,followedby6k+4elementsofsize
1
4
+,followedby12k+8elements
ofsize
1
4
−2.Figure10.28showsthattheoptimalpackingrequires9k+6bins,but
ﬁrstﬁtdecreasinguses11k+8bins.SetM=9k+6,andtheresultfollows.
Inpractice,ﬁrstﬁtdecreasingperformsextremelywell.Ifsizesarechosenuniformly
overtheunitinterval,thentheexpectednumberofextrabinsis(
M).Binpackingisa
ﬁneexampleofhowsimplegreedyheuristicscangivegoodresults.
10.2 DivideandConquer
Anothercommontechniqueusedtodesignalgorithmsisdivideandconquer.Divide-and-
conqueralgorithmsconsistoftwoparts:
Divide:Smallerproblemsaresolvedrecursively(except,ofcourse,basecases).
Conquer:Thesolutiontotheoriginalproblemisthenformedfromthesolutionstothe
subproblems.
divide-and-conqueralgorithms,whileroutineswhosetextcontainsonlyonerecursivecall
468
Chapter10 AlgorithmDesignTechniques
arenot.Wegenerallyinsistthatthesubproblemsbedisjoint(thatis,essentiallynonover-
lapping).Letusreviewsomeoftherecursivealgorithmsthathavebeencoveredinthis
text.
anO(NlogN)solutiontothemaximumsubsequencesumproblem.InChapter4,wesaw
linear-timetreetraversalstrategies.InChapter7,wesawtheclassicexamplesofdivideand
conquer,namelymergesortandquicksort,whichhaveO(NlogN)worst-caseandaverage-
casebounds,respectively.
Wehavealsoseenseveralexamplesofrecursivealgorithmsthatprobablydonotclas-
sifyasdivide-and-conquer,butmerelyreducetoasinglesimplercase.InSection1.3,we
sawasimpleroutinetoprintanumber.InChapter2,weusedrecursiontoperformefﬁ-
cientexponentiation.InChapter4,weexaminedsimplesearchroutinesforbinarysearch
trees.InSection6.6,wesawsimplerecursionusedtomergeleftistheaps.InSection7.7,
analgorithmwasgivenforselectionthattakeslinearaveragetime.Thedisjointset
find
operationwaswrittenrecursivelyinChapter8.Chapter9showedroutinestorecoverthe
shortestpathinDijkstra’salgorithmandotherprocedurestoperformdepth-ﬁrstsearchin
graphs.Noneofthesealgorithmsarereallydivide-and-conqueralgorithms,becauseonly
onerecursivecallisperformed.
We have also seen,in Section 2.4,a very y bad recursive e routine to compute the
inefﬁcient,becausetheproblemreallyisnotdividedatall.
ﬁrstapplicationisaproblemincomputationalgeometry.GivenNpointsinaplane,we
willshowthattheclosestpairofpointscanbefoundinO(NlogN)time.Theexercises
describesomeotherproblemsincomputationalgeometrywhichcanbesolvedbydivide
andconquer.Theremainderofthesectionshowssomeextremelyinteresting,butmostly
theoretical,results.WeprovideanalgorithmthatsolvestheselectionprobleminO(N)
worst-casetime.Wealsoshowthat2N-bitnumberscanbemultipliedino(N
2
)operations
andthattwoN×Nmatricescanbemultipliedino(N
3
)operations.Unfortunately,even
thoughthesealgorithmshavebetterworst-caseboundsthantheconventionalalgorithms,
nonearepracticalexceptforverylargeinputs.
10.2.1 RunningTimeofDivide-and-ConquerAlgorithms
Alltheefﬁcientdivide-and-conqueralgorithmswewillseedividetheproblemsintosub-
problems,eachofwhichissomefractionoftheoriginalproblem,andthenperformsome
sortoperatesontwoproblems,eachofwhichishalfthesizeoftheoriginal,andthen
conditions)
T(N)=2T(N/2)+O(N)
WesawinChapter7thatthesolutiontothisequationisO(NlogN).Thefollowingtheorem
canbeusedtodeterminetherunningtimeofmostdivide-and-conqueralgorithms.
10.2 DivideandConquer
469
Theorem10.6
ThesolutiontotheequationT(N)=aT(N/b)+(N
k
),wherea≥1andb>1,is
T(N)=
O(N
log
b
a
)
ifa>b
k
O(N
k
logN) ifa=b
k
O(N
k
)
ifa<b
k
Proof
FollowingtheanalysisofmergesortinChapter7,wewillassumethatNisapowerof
b;thus,letN=bm.ThenN/b=bm−1 andNk=(bm)
k
=bmk =bkm=(bk)m.Letus
assumeT(1)=1,andignoretheconstantfactorin(N
k
).Thenwehave
T(b
m
)=aT(b
m−1
)+(b
k
)
m
Ifwedividethroughbya
m
,weobtaintheequation
T(b
m
)
am
=
T(b
m−1
)
am−1
+
b
k
a
m
(10.3)
Wecanapplythisequationforothervaluesofm,obtaining
T(b
m−1
)
am−1
=
T(b
m−2
)
am−2
+
b
k
a
m−1
(10.4)
T(bm−2)
am−2
=
T(bm−3)
am−3
+
bk
a
m−2
(10.5)
.
.
.
T(b
1
)
a1
=
T(b
0
)
a0
+
b
k
a
1
(10.6)
T(b
m
)
am
=1+
m
i=1
b
k
a
i
(10.7)
=
m
i=0
bk
a
i
(10.8)
Thus
T(N)=T(b
m
)=a
m
m
i=0
b
k
a
i
(10.9)
470
Chapter10 AlgorithmDesignTechniques
Ifa>b
k
,thenthesumisageometricserieswithratiosmallerthan1.Sincethesum
ofinﬁniteserieswouldconvergetoaconstant,thisﬁnitesumisalsoboundedbya
constant,andthusEquation(10.10)applies:
T(N)=O(a
m
)=O(a
log
b
N
)=O(N
log
b
a
)
(10.10)
Ifa=b
k
,theneachterminthesumis1.Sincethesumcontains1+log
b
Ntermsand
a=b
k
impliesthatlog
b
a=k,
T(N)=O(a
m
log
b
N)=O(N
log
b
a
log
b
N)=O(N
k
log
b
N)
=O(N
k
logN)
(10.11)
Finally,ifb
k
,thenthetermsinthegeometricseriesarelargerthan1,andthe
secondformulainSection1.2.3applies.Weobtain
T(N)=a
m
(bk/a)m+1−1
(bk/a)−1
=O(a
m
(b
k
/a)
m
)=O((b
k
)
m
)=O(N
k
)
(10.12)
provingthelastcaseofthetheorem.
Asanexample,mergesorthasa=b=2andk=1.Thesecondcaseapplies,giving
1applieshere,givingaboundofO(N
log
2
3
)=O(N
1.59
).Analgorithmthatsolvedthree
half-sizedproblems,butrequiredO(N
2
)worktomergethesolution,wouldhaveanO(N
2
)
runningtime,sincethethirdcasewouldapply.
TherearetwoimportantcasesthatarenotcoveredbyTheorem10.6.Westatetwo
moretheorems,leaving theproofsasexercises.Theorem10.7generalizes theprevious
theorem.
Theorem10.7
ThesolutiontotheequationT(N)=aT(N/b)+(Nklog
p
N),wherea≥1,b> 1,
andp≥0is
T(N)=
O(N
log
b
a
)
ifa>b
k
O(N
k
log
p+1
N) ifa=b
k
O(N
k
log
p
N)
ifa<b
k
Theorem10.8
If
k
i=1
α
i
<1,thenthesolution totheequationT(N) =
k
i=1
T
i
N)+O(N)is
T(N)=O(N).
10.2.2 Closest-PointsProblem
The input toour ﬁrst problem is alist of points in aplane.Ifp
1
= (x
1
,y
1
)and
p
2
=(x
2
,y
2
),thentheEuclideandistancebetweenp
1
andp
2
is[(x
1
x
2
)
2
+(y
1
y
2
)
2
]
1/2
.
10.2 DivideandConquer
471
Wearerequiredtoﬁndtheclosestpairofpoints.Itispossiblethattwopointshavethe
sameposition;inthatcase,thatpairistheclosest,withdistancezero.
IfthereareNpoints,thenthereareN(N−1)/2pairsofdistances.Wecancheckall
ofthese,obtainingaveryshortprogram,butattheexpenseofanO(N2)algorithm.Since
thisapproachisjustanexhaustivesearch,weshouldexpecttodobetter.
O(NlogN)totheﬁnaltimebound.SincewewillshowanO(NlogN)boundfortheentire
algorithm,thissortisessentiallyfree,fromacomplexitystandpoint.
Figure10.29showsasmallsamplepointset,P.Sincethepointsaresortedbyxcoor-
dinate,wecandrawanimaginaryverticallinethatpartitionsthepointsetintotwohalves,
P
L
andP
R
.Thisiscertainlysimpletodo.Nowwehavealmostexactlythesamesituation
aswesawinthemaximumsubsequencesumprobleminSection2.4.3.Eithertheclosest
pointsarebothinP
L
,ortheyarebothinP
R
,oroneisinP
L
andtheotherisinP
R
.Letus
callthesedistancesd
L
,d
R
,andd
C
.Figure10.30showsthepartitionofthepointsetand
thesethreedistances.
Wecancomputed
L
andd
R
recursively.Theproblem,then,istocomputed
C
.Sincewe
wouldlikeanO(NlogN)solution,wemustbeabletocomputed
C
Letδ = = min(d
L
,d
R
).Theﬁrstobservationisthatweonlyneedtocomputed
C
ifd
C
improvesonδ.Ifd
C
C
mustbewithin
δofthedividingline;wewillrefertothisareaasastrip.As shownin Figure10.31,
this observationlimits thenumber ofpointsthatneed tobeconsidered(in ourcase,
δ=d
R
).
Therearetwostrategiesthatcanbetriedtocomputed
C
.Forlargepointsetsthatare
uniformlydistributed,thenumberofpointsthatareexpectedtobeinthestripisvery
small.Indeed,itiseasytoarguethatonlyO(
N)pointsareinthestriponaverage.Thus,
wecouldperformabrute-forcecalculationonthesepointsinO(N)time.Thepseudocode
Figure10.29 Asmallpointset