Vous êtes sur la page 1sur 4

InternationalResearchJournalofEngineeringandTechnology(IRJET)eISSN:23950056

Volume:04Issue:01|Jan2017www.irjet.netpISSN:23950072

AcomparativeStudyofSortingAlgorithms
Comb,CocktailandCountingSorting
AhmadH.Elkahlout1,AshrafY.A.Maghari2.
FacultyofInformationTechnology,IslamicUniversityofGazaPalestine
1

FacultyofInformationTechnology,IslamicUniversityofGazaPalestine
2

***
AbstractThesortingalgorithmsproblemisprobablyone javaprogramminglanguage,inwhicheveryalgorithmsort
ofthemostfamousproblemsthatusedinabroadvarietyof thesamesetofrandomnumericdata.Thentheexecution
time during the sorting process is measured for each
application.Therearemanytechniquestosolvethesorting
algorithm.
problem. In this paper, we conduct a comparative study to
evaluatetheperformanceofthreealgorithms;comb,cocktail Therestpartofthispaperisorganizedasfollows.Section2
andcountsortingalgorithmsintermsofexecutiontime.Java givesabackgroundofthethreealgorithms;comb,count,and
programing is used to implement the algorithms using cocktailalgorithms.Insection3,relatedworkispresented.
numeric data on the same platform conditions. Among the Section4 comparison between the algorithms; section 5
threealgorithms,wefoundoutthatthecocktailalgorithmhas discussestheresultsobtainedfromtheevaluationofsorting
theshortestexecutiontime;whilecountingsortcomesinthe techniquesconsidered.Thepaperisconcludedinsection6.
secondorder.Furthermore,Combcomesinthelastorderin
term of execution time. Future effort will investigate the 2.Background
memoryspacecomplexity.

2.1.CombSort
Comb sort is an enhanced version from bubble sort and
KeyWords:Sorting,Comb,Cocktail,Counting,
rediscoveredbyStephenLaceyandRichardBoxin1991.[9].
Algorithm,Comparison,Experimental. Comb Sort is mainly an improvement over Bubble Sort.
Bubble sort always compares adjacent values. So,
1.Introduction allinversionsareremovedonebyone.CombSortimproves
onBubbleSortbyusinggapofsizemorethan1.Thegap
Sortingalgorithmistheprocessofplacingelementsfroma starts with a large value and shrinks by a factor of 1.3 in
collectioninsomekindoforder.Forexample,alistofwords everyiterationshownin igure2untilitreachesthevalue1.
couldbesortedalphabeticallyorbylength.Alistofcities Thus, Comb Sort removes more than oneinversion
couldbesortedbypopulation,byarea,orbyzipcode[1]. countswithoneswapandperformsbetterthanBubbleSort.
The mostused orders are numerical order and Figure 1 shows how Comb sorting algorithm works. In
lexicographicalorder[2].Thesortingisaproblemofcentral average it works better than Bubble Sort. Its worst case,
importance both in theoretical and practical computing however,remainsO(n2).
[3].Efficientsortingisimportantforoptimizingtheuseof
other algorithms such as search and merge algorithms
whichrequireinputdatatobeinsortedlists.Further,the
dataisoftentakentobeinanarray,whichallowsrandom
access, rather than a list, which only allows sequential
access.Thesortingnalgorithmscanbeappliedwithsuitable
modification to either type of data. Since the dawn of
computing,thesortingproblemhasattractedagreatdealof
research, perhaps due to the complexity of solving it
efficiently despite its simple, familiar statement. We have
alreadyseenanumberofalgorithmsthatwereabletosort
unsorted list by different ways and solve the sorting
problem.Computersortingalgorithmscanbeclassifiedinto
two categories; comparisonbased sorting and non
comparisonbased sorting. The purpose of this study is
making experimental comparison between three sorting
algorithmComb,CocktailandCountingSorttodetermine
experimentallywhichoneisthefastestintermofexecution Figure1:Combsort
time. Three sorting algorithms are implemented using by

2017,IRJET|ImpactFactorvalue:5.181|ISO9001:2008Certi iedJournal|Page1387

InternationalResearchJournalofEngineeringandTechnology(IRJET)eISSN:23950056
Volume:04Issue:01|Jan2017www.irjet.netpISSN:23950072


Figure4:Pseudocode:CocktailAlgorithm

Figure2:Pseudocode:combAlgorithm
2.3.CountingSort:

Countingsortisanalgorithmforsortingacollectionof
2.2.CocktailSort:
objectsaccordingtokeysthataresmallintegers.Figure5
showsapseudocodeforthecountingsort.Itoperatesby
Cocktailsortissimilartothebubblesortinwhichbothare
counting the number of objects that have distinct key
evenandcomparisonbasedsortingalgorithmsasshownin
value,andusingarithmeticonthosecountstodetermine
Figure4.TheCocktailalgorithmdiffersfromabubblesortin
thepositionsofeachkeyvalueintheoutputsequence[5].
thatitsortsinbothdirectionsoneachpassthroughthelist
Animportantpropertyofcountingsortisthatitisstable:
asshowninFigure3.Thissortingalgorithmismoredifficult
numberswiththesamevalueappearintheoutputarray
toimplementthanthebubblesort[4].Thefirstrightward
inthesameorderastheydointheinputarrayasshown
passwillshiftthelargestelementtoitscorrectplaceatthe
inFigure6.Thatis,itbreakstiesbetweentwonumbersby
end,andthefollowingleftwardpasswillshiftthesmallest
therulethatwhichevernumberappearsfirstintheinput
element to its correct place at the beginning. The second
arrayitalsoappearsfirstintheoutputarray. Normally,
complete pass will shift the second largest and second
thepropertyofstabilityisimportantonlywhensatellite
smallestelementstotheircorrectplaces,andsoon.
dataarecarriedaroundwiththeelementbeingsorted.
Countingsortsstabilityisimportantforanotherreason:
countingsortisoftenusedasasubroutineinradixsort,in
orderforradixsorttoworkcorrectly,countingsortmust
bestable[3].


Figure3:cocktailsort

Figure5:pseudocode:countingsort

2017,IRJET|ImpactFactorvalue:5.181|ISO9001:2008Certi iedJournal|Page1388

InternationalResearchJournalofEngineeringandTechnology(IRJET)eISSN:23950056
Volume:04Issue:01|Jan2017www.irjet.netpISSN:23950072

operatingsystemwindows764bt.Table2showstheCPU
executiontimeforthethreealgorithms.Weusenumeric
databetween10and3000.Figure7showsagraphical
representation of the execution time of the three
+ +
algorithms. The results demonstrate that the cocktail
algorithms have the shortest execution time; while
counting sort comes in the second order. Furthermore
combcomesinthelastorderintermofexecutiontime.

Figure6:Countingsort
Table1:ExecutiontimemeasuredwithCPUwithvarious
data
3.Relatedwork
Procession Time
Number
Computer sorting algorithms can be classified into two Comb Counting
Cocktail
categories, comparisonbased and noncomparisonbased
sorting. In recent years, some improved algorithms have 15 6 1 3
been proposed to speed up comparisonbased sorting 53 19 1 5
algorithms,suchasadvancedquicksortaccordingtodata 99 39 2 10
distributioncharacteristics[6].Mishra,A.D.andGarg,D.[3] 190 100 4 28
reportedthattheexecutionofanycountingorcomputation 370 220 9 50
refers to the sorting algorithm performance. Like any 550 422 13 79
computationalproblem,similarresultsaregivenfrommany
750 499 17 106
solutions. In [7], the author evaluatesthe performance of
850 850 22 122
three algorithms; insertion, selection, and bubble sorting
950 1250 50 266
algorithms. Their work is evaluated in terms of CPU
3000 1980 66 380
execution time and memory space. The most efficient
Average 538.5 18.5 104.9
algorithmwastheinsertionsort.Selectionsortcameinthe
second order and in the last order came the bubble sort.
Khalid Suleiman AlKharabsheh [9][10] et al. suggested a
GCS(GroupingComparisonSorting)algorithmwhichmakes
further comparison with others conventional sorting
algorithms like Bubble sort, Merge sort, Insertion sort,
QuicksortandSelectionsort,toshowhowthesealgorithms
reducetimeofexecution.
Ourwork,however,isdifferentinthecontextthatthe
experimentalcomparisonisconductedbetweenthree
sortingalgorithms;Comb,CocktailandCountingSortin
termofexecutiontime.
Figure7:CPUTimevs.DataSize
4.ExperimentalResult


In our experiments, the three sorting algorithms have Table2:runningtimeforComb,CocktailandCounting
beenimplementedusingJavaprogramming.Then,time
measuring method is developed to determine the Algorithm Averagecase Worstcase Bestcase
execution time for each algorithm. A set of random Cocktail O(n2) O(n2) O(n)
numericdata is between 10 and 3000. The algorithms Count O(n+k) O(n+k) O(n+k)
wereimplementedinJavalanguage.Thesewererunon Comb O(n2) O(n2) (n log n)
Intel core (R) i52410m, CPU 20.30GHz, RAM 4 G,

2017,IRJET|ImpactFactorvalue:5.181|ISO9001:2008Certi iedJournal|Page1389

InternationalResearchJournalofEngineeringandTechnology(IRJET)eISSN:23950056
Volume:04Issue:01|Jan2017www.irjet.netpISSN:23950072

5.Discussion 9.KhalidSuleimanAlKharabsheh,IbrahimMahmoud
AlTurani,AbdallahMahmoudIbrahimAlTurani,and
Thissectionpresentsthediscussionofresultsobtainedfrom NabeelImhammedZanoon,ReviewonSorting
evaluation of comb, cocktail, and count sort algorithms. AlgorithmsAComparativeStudy,InternationalJournal
Cocktail have variation fromcomb sort and count sort in ofComputerScienceandSecurity(IJCSS),Vol.7,No.3,
2013
whichitpassesalternatelyfrombottomtotopandthenfrom
toptobottom[8].Itcanachieveslightlybetterperformance 10.I.trini,k.kharabsheh,andA.trini,"Grouping
thancountandcombsort.Thereasonforthisisthatcomb ComparisonSort",AustralianJournalofBasicand
andcountonlypassesthroughthelistinonedirection. AppliedSciences,pp.221228,May2016.

6.Conclusion BIOGRAPHIES

Wehaveevaluatedtheperformanceofcomb,cocktail,and Mr. Ahmad H. Elkahlout is


countsorttechniquesusingCPUtime.Thiswasachievedby the corresponding author of
reviewingliteraturesofrelevantworks.Wealsoformulated thispaperandamasterstudent
architectural model which serves as guideline for at the Faculty of Information
Technology,IslamicUniversity
implementing and evaluating the sorting techniques. The
ofGaza,Palestine.
techniqueswereimplementedwithJavalanguage.Empirical PhoneNumber:+97299604246
results were tabulated and graphically presented. The email:a_h_k80@hotmaill.com
results obtained show that in majority of the cases
considered,cocktailsorttechniqueisfaster.Whilecounting
sortcomesinthesecondorderandCombcomesinthelast
order in term of execution time. Future efforts should be
madetocomparethememoryusageofsortingalgorithms.

7.References

1. Huang,Z.,S.Kannan,andS.Khanna.Algorithmsforthe
generalizedsortingproblem.inFoundationsof
ComputerScience(FOCS),2011IEEE52ndAnnual
Symposiumon.2011.IEEE.
2. Demuth,H.B.,Electronicdatasorting.IEEEtransactions
oncomputers,1985.100(4):p.296310.
3. Mishra,A.D.andD.Garg,Selectionofbestsorting
algorithm.InternationalJournalofIntelligent
Informa onProcessing,2008.2(2):p.363368.
4. Cormen,T.H.,etal.,Introductiontoalgorithms.Vol.6.
2001:MITpressCambridge.
5. Adhikari,P.,ReviewOnSortingAlgorithmsA
comparativestudyontwosortingalgorithms.
MississippiState,Mississippi,2007.4.
6. Horsmalahti,P.,ComparisonofBucketSortandRADIX
Sort.arXivpreprintarXiv:1206.3511,2012.
7. Aremu,D.,etal.,AComparativeStudyofSorting
Algorithms.AfricanJournalofCompu ng&ICT,2013.
6(5).
8. Cunningham,J.G.,etal.Methodsforidentifying
systematicdifferentialreflectivity(ZDR)biasesonthe
operationalWSR88Dnetwork.in36thConferenceon
RadarMeteorology.2013.

2017,IRJET|ImpactFactorvalue:5.181|ISO9001:2008Certi iedJournal|Page1390