4
We b Site : ww w.ij e ttcs .org Em ail: e ditor@ij e ttcs .org, e ditorij e ttcs @gm ail.co m Volum e 2 , I s sue 1 , J anua ry – Fe bruary 2013 I SSN 22 78 -685 6  Volume 2, Issue 1 January - February 2013 Page 204 ABSTRACT: Sorting i nvo lve s rearrang ing inf orma tion i nto either ascending or descending order. There are many sorting algorithms; Sorting has been an area of interest for all those who have been involved into the mining field of data. Sorting dat a i s imp ortant to se arch the data a pp ropri ate ly. F or different types of works different types of sorting algorithm has be en propose d by different sc ientist. There are seve ral issue s w ith sorti ng to taken into account but I n this pap e r, w e will compare the bubble sort with binary sort then merge them to take the be tter pe rformance of be focusi ng on the time factor of the sorting. This research is about comparing and merging such an algorithm which fits into each and every account of sorti ng and searches the d ata app ropri ate ly. For the sam e we will have to look into the previous done algori thms also and then we would have to com pare the previous work with our latest done work.  K e yw o r ds : Sorting, algorithms, comparison, bubble sort, binary sort, merge sort. 1.  INTRODUCTION I n thi s pape r we ha ve se en that the re are dif f e re nt types o f  sorting and their internal structure. Now let’s get to know what exactly are the problems in sorting .The first problem is selecting the best suited algorithm for sorting.  Th e S e le ct io n S o rt is u se d fo r s e le ct in g t h e a lg o rit h m.  Th ere are man y so rt in g a lg o rit h ms. All s ort in g a lg o rit h m are for different kind of problem .To choose an algorithm de pe nds upon what kind of structure we do have . Accordingly the archite cture and com ple xity is diffe rent. Hence we nee d to d es ign a kind of binary al gori thm for sorting which can fit in m ost of the c as e s. I f we w ould like to com pare the b ubb le al gori thms , i t doe s ha ve diffe re nt scena rio. We can m e rge them according to the com plexity which they posse ss. I t is also ne ces sary that we choose the be st cate gory, i.e. whether internal or exte rnal sorti ng algori thm. Now wha teve r we choose as an a lgorithm , our aim is to e m pha sis on t he tim ing factor. By ti m ing factor I m e an tha t how m uch tim e it take s to exe cute the s tructure of the s ea rching. Hence our aim is to com pare the b e st suited g ene rated a lgori thm for sea rching in terms of time compatibility. 1 .1 Ins e r tion So r t:-I ns e rtio n s ort is a simple a comparison sorting algorithm. Every iteration of insertion sort rem ove s an e lem ent from the input da ta, inse rting it into the correct position in the already-sorted list, until no input elem e nts re m ain. The cho ice of which elem ent to remo ve from the i nput is a rbi trary, and can be ma de using a lm os t any ch oice a lgo ri thm . Illust ration of i nse rtion so rt for input list [5, 2, 4, 6, 1, 3]: 1.2 Selection Sort:-Selection sort is also a simple a comparison sorting algorithm. The algorithm works as follows: 1. Find the minimum value in the list 2. Swap it with the value in the first position 3. Rep ea t the steps a bove f or the rem ainder of the l ist (starting at the se cond pos ition a nd adva ncing ea ch ti me ) Figure 1.2: Example of straight selection sort list [1,3,4,5,7]: 2 . REL AT ED WORK A sorting algori thm is a n algori thm that p uts e le m e nts of  a list in a ce rtain order. The m ost-use d orde rs are numerical order and lexicographical order. Efficient so rti ng is im portant for optim izi ng the use of othe r al gori thms such a s se arch and me rge a lgori thms which require input data to be in sorted lists; it is also often useful for data and for producing huma n-rea da ble Output. More formally, the output must satisfy two conditions.  Th e outpu t is in non d ecreas in g o rd er eac h e le ment is no sm al ler than the previ ous elem ent a ccordi ng to the de sired tota l order. The output is a pe rmu tati on reordering of the input. 2.1 BUBBL E SORT Although the shell sort algorithm is significantly better than insertion sort, there is still room for improvement. One of the most popular sorting algorithms is quick sort. Quick sort executes in O ( n lo g n ) on average a nd O ( n 2) in the worst-case . Howe ver, with prope r preca utions, worst-case be havior is ve ry unli ke ly. Quick so rt i s a non-sta ble s ort. I t is no t a n in- place sort as s tac k spac e is requ ired. The q uick sort algori thm wo rks by pa rti tioning the a rray t o be sorted, the n re curs ive ly so rti ng e a ch pa rtition. I n Partition, one Study of Sorting Algorithm to Optimize Search Results Savina 1 , Sur m e e t K au r 2  1 ,2 Depa rtma en t of Comp ute r Scien ce a nd Enginee ri ng Lovely profes siona l university, J alandh ar, I nd ia

Study of Sorting Algorithm to Optimize Search Results

Embed Size (px)

Citation preview

Page 1: Study of Sorting Algorithm to Optimize Search  Results

7/29/2019 Study of Sorting Algorithm to Optimize Search Results

http://slidepdf.com/reader/full/study-of-sorting-algorithm-to-optimize-search-results 1/4

Web Site: www.ijettcs.org Email: [email protected], [email protected] 2, Issue 1, J anuary – February 2013 ISSN 2278-6856 

Volume 2, Issue 1 January - February 2013 Page 204

ABSTRACT: Sorting involves rearranging information into

either ascending or descending order. There are many sorting

algorithms; Sorting has been an area of interest for all those

who have been involved into the mining field of data. Sortingdata is important to search the data appropriately. For

different types of works different types of sorting algorithmhas been proposed by different scientist. There are severalissues with sorting to taken into account but In this paper, we

will compare the bubble sort with binary sort then merge

them to take the better performance of be focusing on thetime factor of the sorting. This research is about comparing

and merging such an algorithm which fits into each and

every account of sorting and searches the data appropriately.For the same we will have to look into the previous done

algorithms also and then we would have to compare the

previous work with our latest done work. Keywords: Sorting, algorithms, comparison, bubble sort,binary sort, merge sort.

1. INTRODUCTION

In this paper we have seen that there are different types of sorting and their internal structure. Now let’s get to knowwhat exactly are the problems in sorting .The firstproblem is selecting the best suited algorithm for sorting. The Selection Sort is used for selecting the algorithm. There are many sorting algorithms. All sorting algorithmare for different kind of problem .To choose an algorithmdepends upon what kind of structure we do have.Accordingly the architecture and complexity is different.Hence we need to design a kind of binary algorithm for

sorting which can fit in most of the cases. If we wouldlike to compare the bubble algorithms, it does havedifferent scenario. We can merge them according to thecomplexity which they possess. It is also necessary thatwe choose the best category, i.e. whether internal orexternal sorting algorithm. Now whatever we choose asan algorithm, our aim is to emphasis on the timing factor.By timing factor I mean that how much time it takes toexecute the structure of the searching. Hence our aim is tocompare the best suited generated algorithm for searchingin terms of time compatibility.1.1 Insertion Sort:-I nsertion sort is a simple acomparison sorting algorithm. Every iteration of insertion

sort removes an element from the input data, inserting itinto the correct position in the already-sorted list, until noinput elements remain. The choice of which element toremove from the input is arbitrary, and can be made using

almost any choice algorithm. Illustration of insertion sortfor input list [5, 2, 4, 6, 1, 3]:

1.2 Selection Sort:-Selection sort is also a simple acomparison sorting algorithm. The algorithm works asfollows:1. Find the minimum value in the list2. Swap it with the value in the first position3. Repeat the steps above for the remainder of the list(starting at the second position and advancing each time)Figure 1.2: Example of straight selection sort list[1,3,4,5,7]:

2. REL ATED WORK A sorting algorithm is an algorithm that puts elements of a list in a certain order. The most-used orders arenumerical order and lexicographical order. Efficientsorting is important for optimizing the use of otheralgorithms such as search and merge algorithms whichrequire input data to be in sorted lists; it is also often

useful for data and for producing human-readable Output.More formally, the output must satisfy two conditions. The output is in non decreasing order each element is nosmaller than the previous element according to thedesired total order. The output is a permutationreordering of the input.

2.1 BUBBL E SORT Although the shell sort algorithm issignificantly better than insertion sort, there is still roomfor improvement. One of the most popular sortingalgorithms is quick sort. Quick sort executes in O (n logn) on average and O (n2) in the worst-case. However,with proper precautions, worst-case behavior is very

unlikely. Quick sort is a non-stable sort. It is not an in-place sort as stack space is required. The quick sortalgorithm works by partitioning the array to be sorted,then recursively sorting each partition. In Partition, one

Study of Sorting Algorithm to Optimize Search

ResultsSavina1, Surmeet Kaur2 

1,2Departmaent of Computer Science and Engineering Lovely professional university, Jalandhar, India

Page 2: Study of Sorting Algorithm to Optimize Search  Results

7/29/2019 Study of Sorting Algorithm to Optimize Search Results

http://slidepdf.com/reader/full/study-of-sorting-algorithm-to-optimize-search-results 2/4

Web Site: www.ijettcs.org Email: [email protected], [email protected] 2, Issue 1, J anuary – February 2013 ISSN 2278-6856 

Volume 2, Issue 1 January - February 2013 Page 205

of the array elements is selected as a pivot value. BubbleSort is not known to be a good algorithm because it is aquadratic-time sorting algorithm. However, efforts havebeen made to improve the performance of the algorithm.

With Bidirectional Bubble Sort, the average number of comparisons is slightly reduced and Batcher’s Sortsimilar to Shell sort also performs significantly betterthan Bidirectional Bubble Sort by carrying outcomparisons in a novel way so that no propagation of exchange is necessary. Bubble sort is a simple sortingalgorithm. It works by repeatedly stepping through thelist to be sorted, comparing each pair of adjacent itemsand swapping them if they are in the wrong order. Firstpass bubble out the largest element and places in the lastposition and second pass place the second largest in thesecond last position and so on. Thus, in the last passsmallest items is placed in the first position. Because, it

only uses comparisons to operate on elements, it is a

comparison sort.For I =1: n,

Swapped =falseFor j =n: i+1,

If a[j] <a [j-1],Swap a [j,j-1]Swapped =true

Break if not swappedEnd

Example: - Bubble sort (sorted elements are shaded)

23 78 45 8 32 56 Original ListUnsorted

8 23 78 45 32 56 after Pass 1Unsorted

8 23 32 78 45 56 after Pass 2Sorted Unsorted8 23 32 45 78 56 after Pass 3

Sorted Unsorted8 23 32 45 56 78 after Pass 4

Sorted Sorted

2.2 BINARY SORT:-In computer science, abinary sort algorithm finds the position of a specified value within a

sorted array. In each step, the algorithm compares theinput key value with the key value of the middle elementof the array. If the keys match then a matching elementhas been found so its index, or position, is returned.Otherwise, if the sought key is less than the middleelement's key, then the algorithm repeats its action on thesub-array to the left of the middle element or, if the inputkey is greater, on the sub-array to the right. If theremaining array to be searched is reduced to zero, thenthe key cannot be found in the array and a special "Notfound" indication is returned. However, if we place ouritems in an array and sort them in either ascending ordescending order on the key first, then we can obtain

much better performance with an algorithm called BinarySort. These are following functions in this paper whichcan be implemented in Binary Sort Order:

1. Bin sort is recursive: it determines whether the searchkey lies in the lower or upper half of the array, then callsitself on the appropriate half.2. There is a termination condition two of them in fact!

If low>high then the partition to be searched hasno elements in itand If there is a match with the element in the middleof the current partition, then we can returnimmediately.

3. AddToCollection will need to be modified to ensurethat each item added is placed in its correct place in thearray. The procedure is simple:

Search the array until the correct spot to insert thenew item is found,Move all the following items up one positionand 

Insert the new item into the empty position thuscreated.

4. Bin search is declared static. It is a local function andis not used outside this class and if it were not declaredstatic, it would be exported and be available to all parts of the program. The static declaration also allows otherclasses to use the same name internally.

Each step of the algorithm divides the block of items

being searched in half. We can divide a set of n items inhalf at most log2 n times. Thus the running time of a

binary search is proportional to log n and we say this is

an O (log n) algorithm. Binary search requires a morecomplex program than our original search and thus forsmall n it may run slower than the simple linear search.However, for large n, lim log n \ n =0. Thus at large n,log n is much smaller than n, consequently an O (log n)algorithm is much faster than an O (n) one. In worstcase, insertion may require n operation to insert into asorted list. We can find the place in the list where the newitem belongs using binary search in O (log n) operations.

However, we have to shuffle all the following items upone place to make way for the new one. In the worst case,the new item is the first in the list, requiring n moveoperations for the shuffle. A similar analysis will showthat deletion is also an O (n) operation. If our collection isstatic it doesn't change very often - if at all - then we maynot be concerned with the time required to change itscontents: we may be prepared for the initial build of thecollection and the occasional insertion and deletion totake some time. In return, we will be able to use a simpledata structure which has little memory overhead.However, if our collection is large and dynamic, i.e. itemsare being added and deleted continually, and then we can

obtain considerably better performance using a datastructure called a tree.

Page 3: Study of Sorting Algorithm to Optimize Search  Results

7/29/2019 Study of Sorting Algorithm to Optimize Search Results

http://slidepdf.com/reader/full/study-of-sorting-algorithm-to-optimize-search-results 3/4

Web Site: www.ijettcs.org Email: [email protected], [email protected] 2, Issue 1, J anuary – February 2013 ISSN 2278-6856 

Volume 2, Issue 1 January - February 2013 Page 206

2.3 MERGE SORT: - Merge sort takes advantage of theease of merging already sorted lists into a new sorted list.Merge sort is good for data that's too big to have inmemory at once because its pattern of storage access isvery regular. It also uses even fewer comparisons withbinary sort and heap sort. It is especially suited for datastored as linked lists. Merge Sort is a O (nlogn) sortingalgorithm. It starts by comparing every two elements i.e.,1 with 2, then 3 with 4... And swapping them if the firstshould come after the second. I t then merges each of theresulting lists of two into lists of four, then merges thoselists of four, and so on; until at last two lists are mergedinto the final sorted list. Of the algorithms described here,this is the first that scales well to very large lists, becauseits worst-case running time is O (n log n). Merge sort hasseen a relatively recent surge in popularity for practicalimplementations, being used for the standard sort routinein the programming languages Perl, Java and amongothers. Merge sort  is an O (n log n) comparison-based

divide and conquer sorting algorithm. Conceptually, amerge sort works as follows:

1. If the list is of length 0 or 1, then it is already sorted.Otherwise:2. Divide the unsorted list into two sub lists of about half the size.3. Sort each sub list recursively by re-applying merge sortalgorithm.4. Merge the two sub lists back into one sorted list.

3. RESULT & DISCUSSION

Sorting algorithms used in computer science are oftenclassified by: Computational complexity worst, averageand best behavior of element comparisons in terms of thesize of the list. For typical sorting algorithms goodbehavior is O (nlogn) and bad behavior is O (n2).Memoryusage and use of other computer resources. In particular,some sorting algorithms are "in place". This means thatthey need only O (1) memory beyond the items beingsorted and they don't need to create auxiliary locations fordata to be temporarily stored, as in other sortingalgorithms. Recursion some algorithms are eitherrecursive or non-recursive, while others may be both e.g.,merge sort. Stability stable sorting algorithms maintain

the relative order of records with equal keys i.e., values.Whether or not they are a comparison sort. A comparisonsort examines the data only by comparing two elementswith a comparison operator. Adaptability Whether or not

the pre sorted of the input affects the running time. Letget to know about two sorting techniques and analyzetheir performance. The two techniques are: 1. InternalSorting, 2. External Sorting.

Comparison of algorithms 

Nam

e

Best Avera

ge

Worst Memory Stabl

e

Method

Bubb

le

Sort

n n n 1 Yes Exchanging

Binar

y

Sort

n nlogn nlogn n Yes Insertion

Merg

eSort

nlogn nlogn nlogn Depends:

Worstcase is n

 Yes Merging

At the result of this paper is in the sorting algorithm isthat the binary sort is merge with bubble sort to obtainbetter performance of the time complexity. In thiscomparison of bubble sort and binary sort there should becheck the complexity of best case, average case and worstcase. Then merge the bubble sort with binary sort andinsertion method is used for binary sort and selectionmethod is used for bubble sort. These algorithms are usedto depend on need.

4. CONCLUSION In this paper, we can use sorting algorithms. We presentdifferent sorting algorithms models. This research isabout finding or creating such an algorithm which fitsinto each and every account of sorting and searches thedata appropriately, such as Bubble Sort, B Sort andMerge Sort. However, we study sorts because generalsorts do not work in all situations and because sorting is asimple illustration of algorithmic techniques. This paperstarted by giving an overview over selected algorithms fortime factor of the sorting, which uncovered bothweaknesses and strengths of existing approaches.

Algorithms should give a time complexity for the selectedset of quality characteristics and explain the relationshipsbetween concepts. This paper has introduced two sortingalgorithms than the merge sorting algorithms. The first isbased upon sorting by the insertion technique, whereasthe second is based upon sorting by the exchangetechnique. The analysis of Merge algorithms shows thatthey score the best performance when binary sort andheap sort can be merged. This paper is best compare toprivies this is compare based on the time, complexity if the current is time is less then thus is the best algorithm.

REFERENCES 

[1] Alfred V, Aho J, Horroroft, Jeffrey DU (2002). DataStructures and Algorithms (India: Pearson EducationAsia).

Page 4: Study of Sorting Algorithm to Optimize Search  Results

7/29/2019 Study of Sorting Algorithm to Optimize Search Results

http://slidepdf.com/reader/full/study-of-sorting-algorithm-to-optimize-search-results 4/4

Web Site: www.ijettcs.org Email: [email protected], [email protected] 2, Issue 1, J anuary – February 2013 ISSN 2278-6856 

Volume 2, Issue 1 January - February 2013 Page 207

[2] A. V. Aho, J. E. Hopcroft, and J. D. Ullman, TheDesign and Analysis of Computer Algorithms,Addison-Wesley, Reading, Massachusetts, [1976].

[3] Aho, Alfred V. and Jeffrey D. Ullman [1983]. Data

Structures and Algorithms. Addison-Wesley,Reading, Massachusetts.[4] Alfred V. Aho, John E. Hopcroft, and Jeffrey D.

Ullman. The Design and Analysis of ComputerAlgorithms. Addison-Wesley, [1974].

[5] Alfred V, Aho J, Horroroft, Jeffrey DU (2002). DataStructures and Algorithms (India: Pearson EducationAsia).

[6] D. E. Knuth, the Art of Computer Programming, Vol.3: Sorting and Searching, Addison-Wesley, Reading,Massachusetts, [1973].

[7] Günter J . Hitsch, Ali Hortaçsu, and Dan Ariely,[2010] “American Economic Review” 2010.

[8] M. Thorup Randomized Sorting in O (n log n) Timeand Linear Space Using Addition, Shift, and Bit-wiseBoolean Operations. Journal of Algorithms, Volume42, Number 2, February 2002.

[9] Owen Astrachan Bubble Sort: An ArchaeologicalAlgorithmic Analysis, SIGCSE ’03, February 19-23,Reno, Nevada, USA. Copyright 2003 ACM 1-58113-648-X/03/0002.

[10] Pearson, Peter K. [2008], “Fast Hashing of Variable-Length Text Strings” Communications of the ACM, June 2008.

[11] R. P. Blake, Exploring a Stack Architecture,

Computer, 10, May [1977].[12] Sultanullah Jadoon, Salman Faiz Solehria, Prof. Dr.

Salim ur Rehman, Prof. Hamid Jan,[2011],” Designand Analysis of Optimized Selection Sort Algorithm”International Journal of Electric & ComputerSciences IJECS-IJENS Vol: 11 No: 01, February2011.

[13] Strowd, Harrison & Lewis, Grace. T-Check inSystem-of-Systems Technologies: Cloud Computing(CMU/SEI-2010-TN-009).Software EngineeringInstitute, Carnegie Mellon University,[2010].

[14] T. L. Booth, and C. A. Wiecek, Performance

Abstract Data Types as a Tool in SoftwarePerformance Analysis and Design, IEEE Trans.Software Eng. [1980].

[15]T. L. Booth, et al., PASS: A Performance-AnalysisSoftware System to Aid the Design of High-Performance Software, Proc. 1st Int. Conf.Computers and Applications; June [1984].

[16] Y . Han. Deterministic sorting in O (n log log n) timeand linear space. Proceedings of the thirty-fourthannual ACM symposium on Theory of computing,Montreal, Quebec, Canada, 2002.

Savina received the MCA degree from Punjab

 Technical University and pursuing M.tech in

Lovely professional university, Jalandhar, India