You are on page 1of 6

Program1Writeup

ADTTimes:
File
File1
File2
File3
File4
File1
File2
File3
File4
File1
File2
File3
File4
File1
File2
File3
File4
File1
File2
File3
File4
File1
File2
File3
File4

ADT#
1
1
1
1
2
2
2
2
3
3
3
3
4
4
4
4
5
5
5
5
6
6
6
6

Time#1
0.107086
57.5857
0.084307
32.8634
0.092807
300.682
0.109212
149.947
0.068985
0.057618
0.057967
0.061039
0.083801
0.069156
0.069105
0.072085
0.074723
0.061192
0.061934
0.065572
0.304766
0.228541
0.265299
0.463072

Time#2
0.108801
57.5804
0.08315
32.5877
0.088998
300.524
0.105518
155.752
0.068959
0.057664
0.057752
0.060822
0.083849
0.07025
0.069781
0.072909
0.074396
0.060715
0.061755
0.065014
0.311911
0.229702
0.270016
0.490939

Time#3
0.108422
57.5366
0.082953
32.631
0.089057
301.347
0.105533
170.386
0.069078
0.057597
0.057881
0.060731
0.083534
0.070618
0.069841
0.072931
0.074214
0.06091
0.061743
0.065093
0.309608
0.232232
0.274708
0.494689

AverageTime
0.108103
57.56756667
0.08347
32.69403333
0.090287333
300.851
0.106754333
158.695
0.069007333
0.057626333
0.057866667
0.060864
0.083728
0.070008
0.069575667
0.072641667
0.074444333
0.060939
0.061810667
0.065226333
0.308761667
0.230158333
0.270007667
0.4829

BigO:
File
1(In)
2(In/Del)
3(In/Delrev
)
4(rand)
1
2
3
4
1
2
3
4
1
2
3
4
1
2
3
4
1
2
3
4

ADT#

Insert

Delete
0

Entire
seriesof
Inserts
N

Seriesof Entire
Deletion File
s
0
N

1(LinkedList
)
1
1

O(1)
O(1)
O(1)

O(n)
O(1)

N
N

N2
N

N2
N

1
2(CursorList)
2
2
2
3(StackAr)
3
3
3
4(StackLi)
4
4
4
5(QueueAr)
5
5
5
6(SkipList)
6
6
6

O(1)
O(1)
O(1)
O(1)
O(1)
O(1)
O(1)
O(1)
O(1)
O(1)
O(1)
O(1)
O(1)
O(1)
O(1)
O(1)
O(1)
logN
logN
logN
logN

O(n)
0
O(N)
O(1)
O(N)
0
O(1)
O(1)
O(1)
0
O(1)
O(1)
O(1)
0
O(1)
O(1)
O(1)
0
logN
logN
logN

N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
N
NlogN
NlogN
NlogN
NlogN

N2
0
N2
N
N2
0
N
N
N
0
N
N
N
0
N
N
N
0
NlogN
NlogN
NlogN

N2
N
N2
N
N2
N
N
N
N
N
N
N
N
N
N
N
N
NlogN
NlogN
NlogN
NlogN

LinkedList
File1runsquicklybecausethelistisnotsorted,thereforeitsimplyinsertsatthe
front,howeveritisslowerthanfile3becauseithastoallocatespaceforeachnewnode
whenitinserts.File3runsthefastestbecausetheitembeingdeletedisalwaysthefirst
iteminthelist.File2takesthelongestbecausetheitembeingdeletedisalwaysatthe
endofthelistandtheprogrambutiterateallthewaytotheendofthelistbeforeit
deletessomething.File4takestheaverageoffile2and3becauseitisrandominsertsand
deletes,andonaverageitsearchesN/2itemsuntilitfindswhattodelete.
CursorList
Thecursorlistalsoalwaysinsertsintothefrontofthelist,causingittotakea
shorttimeforfile1.Itisslightlyslowerthenfile3becauseforeachinsertionitmust
allocateacursornodeandforfile3,theobjectbeingdeletedisthefirstthingchecked.
Forfile2,theobjectbeingdeletedisalwaysattheendofthelist,causingittotakethe
longestpossibletime.Forfile4,ittakesonaverageN/2timebecauseitinsertsand
deletesrandomly,howeverafterthefirstrun,futurerunstakelonger.Thisisbecausethe
cacheonlytakesin64bitsofdata,andeachnodeis~32bits.Eachtimeanodeis
accessed,thenextnode(geographically)isalsopulledintothecacheanditchecksthat
nodealso,causingittotakelesstimetosearchthroughthings.Foreachconsecutiverun,
thecursorSpaceisneverresetbecauseitwasdeclaredglobally.Thisonlyaffectsfile4
becauseoftherandominsertsanddeletes.Bytheendofthefirstrunforfile4,the
cursorSpaceindicespointtorandomotherindices,andwhenthecachetakesin

consecutivenodes,itdoesnotusetheothernodeaccessed,becausethenextindiceofthe
firstnodeissomethingelse.Causingittocauseacachemiss,andforcingittolookfor
thennextnodeintheRAM,whichtakesmoretimethansimplyreadingfromthecache.
StackList/StackArray/QueueArray
Stacksandqueuesperformrelativelythesameonthethreefilescontaining
deletionsbecausetheycouldignoretheactualvaluebeingspecifiedtobedeleted.The
firstfileforstacklisttakesslightlylongerbecauseofthetimeneededtoallocateeach
newnode.Thefirstfileforstackarraytakesslightlylongerbecauseoftimeneededto
checkifthearrayitfullislongerthanthetimeneededtocheckifitisempty
SkipList
File1takeslongerthanfile2and3becauseittakestimetoallocateeachnew
node.Forfile2,thingsarealwaysdeletedfromthefrontofthelist,causingittobethe
fastest.Forfile3,theitembeingdeleteditalwaysthelastthinginthelist,however
becauseofhowtheskiplistcanskiplargeamountsofdata,itskipsmostofthedatavery
quicklyuntilitreachestheendofthelistanddeletesthelastelement.Inthecaseoffile
4,theskiplistmaybepastthevaluebeingdeleted,andwillhavetobacktrackthefindthe
actualvaluetobedeleted,causingittotakelongerthanfile2and3.File4tookthe
longesttimebecauseofreasonsmentionedabove.

ComparingADTs
Regardingstacksandqueues,thestacklisttooklongerthatthestackarray
becausewiththearrayversion,onlytheindexvaluesofthearrayarechangedwhen

popping,andforinserting,youareinsertingavalueintoapreviouslyallocatedspace,
whilethelinkedlistversion,eachtimeanewitemisinserted,youmustallocatespacefor
thenewlistnode,anddeletesalsomustdeallocatethespaceforthelistnodebeing
deleted.Thequeuealsoworksinasimilarlisttothestackarray,howeverthequeue
takeslongerthanthestackarraybecauseitmustkeeptrackoftwoindices(frontand
back),whichcausesittotakeaboutthesametimeasthestacklist.Thearray
implementationoftheseADTsrunsfasterthanthelinkedlistversionalsobecausewith
thearray,allofthedataisstoredgeographicallyclosetoeachotherbecauseitis
allocatedasonelargeblockofmemory,whereasalinkedlistislocatedatrandompoints
inRAM.
ForthelistADTs,theskiplistisgenerallythefastest,becauseitdoesnothaveto
gothrougheveryelementtofindwhereitneedstoinsertordeleteanobject.Onthe
otherhand,thelinkedlistandcursorlistmustiteratethrougheverysingleelementuntil
theyfindwhattheyarelookingfor.Cursorlistworksinasimilarmannertothelinked
list,howeverbecausecursorlistusestheimplementationofvector,ittakeslongerto
deletethanthelinkedlistbecauseoftheextraoperationsrequiredfindthedeletion,and
theoperationspartofthedeletion.Whenadeletionismadeinthelinkedlist,itsimply
changesthepointersonthenodebeforeandafterandfreesthenode.Whenthecursorlist
deletes,itmustspendtimeiteratingthroughthevectorofcursornodesusingvector
operators,andwhenitfindswhatistobedeleted,itchangesthenextindexofthe
previouselementanddeallocatestheitemsbeingdeleted,Thedeallocationtakestwo
steps,firstitdeletestheindexvaluefromthecursorlist,thenitaddstheindextothe

cursorspace(freelist).Ontheotherhand,thecursorlistisfasterforinsertsbecauseit
hasapreviouslyallocatedcursorspacetoallocatecursornodes.Cursorlistandlinked
listhavethesamecomplexities(0(N))yettakedifferenttimesbecauseperform
operationsrelativetoamountofdatabeinginputted.Forexampleeachdeleteinlinked
listchangesthepreviousitemspointerandfreesthenode,andforcursorlistitchange
thepreviousitemsnextindexandfreethenode,thenplacesitbackintothefreelist.For
eachdeletion,theyperformthesesameoperations,howeverthecursorlistmustperform
moreoperationsperdeletion.

You might also like