DataStructuresa
dAlgorithm习题答案
Prefaceii1DataStructuresa
dAlgorithms12MathematicalPrelimi
aries53AlgorithmA
alysis174ListsStacksa
dQueues235Bi
aryTrees326Ge
eralTrees407I
ter
alSorti
g468FileProcessi
ga
dExter
alSorti
g549Searchi
g5810I
dexi
g6411Graphs6912Listsa
dArraysRevisited7613Adva
cedTreeStructures82i
fiiCo
te
ts14A
alysisTech
iques8815LimitstoComputatio
94
fPreface
Co
tai
edherei
arethesolutio
stoallexercisesfromthetextbookAPracticalI
troductio
toDataStructuresa
dAlgorithmA
alysis2
deditio
Formostoftheproblemsrequiri
ga
algorithmIhavegive
actualcodeI
afewcasesIhaveprese
tedpseudocodePleasebeawarethatthecodeprese
tedi
thisma
ualhas
otactuallybee
compileda
dtestedWhileIbelievethealgorithmstobeesse
tiallycorrecttheremaybeerrorsi
sy
taxaswellassema
ticsMostimporta
tlythesesolutio
sprovideaguidetothei
structorastothei
te
deda
swerrathertha
usableprograms
f1DataStructuresa
dAlgorithms
I
structor’s
oteU
liketheotherchaptersma
yofthequestio
si
thischapterare
otreallysuitableforgradedworkThequestio
saremai
lyi
te
dedtogetstude
tsthi
ki
gaboutdatastructuresissues
11Thisquestio
does
othaveaspecificrighta
swerprovidedthestude
tkeepstothespiritofthequestio
Stude
tsmayhavetroublewiththeco
ceptof“operatio
s”12Thisexerciseasksthestude
ttoexpa
do
theirco
ceptofa
i
tegerreprese
tatio
Agooda
swerisdescribedbyProject45whereasi
glyli
kedlistissuggestedThemoststraightforwardimpleme
tatio
storeseachdigiti
itsow
list
odewithdigitsstoredi
reverseorderAdditio
a
dmultiplicatio
areimpleme
tedbywhatamou
tstogradeschoolarithmeticForadditio
simplymarchdow
i
parallelthroughthetwolistsreprese
ti
gtheopera
dsateachdigitappe
di
gtoa
ewlisttheappropriatepartialsuma
dbri
gi
gforwardacarrybitas
ecessaryFormultiplicatio
combi
etheadditio
fu
ctio
witha
ewfu
ctio
thatmultipliesasi
gledigitbya
i
tegerExpo
e
tiatio
ca
bedo
eeitherbyrepeatedmultiplicatio
otreallypracticalorbythetraditio
alΘlog
timealgorithmbasedo
thebi
aryreprese
tatio
oftheexpo
e
tDiscoveri
gthisfasteralgorithmwillbebeyo
dthereachofmoststude
tssoshould
otberequired13AsampleADTforcharacterstri
gsmightlookasfollowswiththe
ormali
terpretatio
ofthefu
ctio
amesassumed
fChap1DataStructuresa
dAlgorithms
Co
cate
atetwostri
gsStri
gstrcatStri
gs1Stri
gs2
Retur
thele
gthofastri
gi
tle
gthStri
gs1
Extractasubstri
gstarti
gat‘start’a
dofle
gth‘le
gth’Stri
gextractStri
gs1i
tstarti
tle
gth
GetthefirstcharactercharfirstStri
gs1
Comparetwostri
gsthe
ormalCstrcmpfu
ctir