Presentation is loading. Please wait.

Presentation is loading. Please wait.

NEW SORTING ALGORITHMS

Similar presentations


Presentation on theme: "NEW SORTING ALGORITHMS"— Presentation transcript:

1 NEW SORTING ALGORITHMS
Ersin Alpan SWE April 22,2008 NEW SORTING ALGORITHMS Gnome Sort Bubble Sort Bingo Sort Bitonic Sort Ersin Alpan

2 Gnome Sort Gnome sort is a sort algorithm which is similar to insertion sort except that moving an element to its proper place is accomplished by a series of swaps, as in bubble sort.

3 Gnome Sort It is conceptually simple, requiring no nested loops. The running time is O(n2), and in practice the algorithm has been reported to run slightly slower than bubble sort, although this depends on the details of the architecture and the implementation.

4 Pseudocode & Example

5 Bubble Sort: The bubble sort algorithm works as follows:
Compare adjacent elements. If the first is greater than the second, swap them. Do this for each pair of adjacent elements, starting with the first two and ending with the last two. At this point the last element should be the greatest. Repeat the steps for all elements except the last one. Keep repeating for one fewer element each time, until you have no more pairs to compare. Due to its simplicity, the bubble sort is often used to introduce the concept of an algorithm to introductory programming students.

6 Bubble Sort:

7 Bubble Sort: " “

8 Bingo Sort In all of the algorithms we have seen so far,the input size was a function of a single variable n.In this sort we have more than one depended variables.These variable may vary depending on the type of the data.For example if we have a list of size n with repeated elements(n>m). Bingo sort works as follows Each distinct value in the list is considered to be a Bingo value.Each pass corresponds to “calling out” is considered to be a bingo value.Bingo values are called out in increasing order.During a given pass all the elements having the current bingo value are placed in their correct positions in the list.

9 Bingo Sort Procedure BingoSort(array of size n) Input:array
Output:sorted array Call MaxMin(array,maxVal,minVal) Bingo:=minVal NextAvail:=1 NextBingo:=maxVal While Bingo<MaxVal do { StartPos=NextAvail for i:=StartPos to n Do if array[i]=Bingo then call InterChange(array[i],array[NextAvail]) NextAvail:=NextAvail+1 else if array[i]<NextBingo then NextBingo:=array[i] Endif endfor Bingo:=NextBingo NextBingo:=MaxVal endwhile endBingoSort

10 Example: Pass Start Position Bingo Value Pass 2 Start Position Bingo Value

11 Complexity Analysis We express the complexity of the Bingo Sort in terms of two variables n and m.For m small than n Bingo Sort has average and worst case complexities in O(mn) and best case complexity O(n + m2).Hence for m<logn Bingo Sort performs better than sorts such as Merge Sort and Heap Sort.

12 Ersin Alpan Figures & Topics: George Karypis
SWE 510 April 22, 2008 BITONIC SORT Ersin Alpan Figures & Topics: George Karypis

13 Sorting Networks: Sorting is one of the fundamental problems in Computer Science For a long time researchers have focused on the problem of “how fast can we sort n elements”? 􀂅 Serial 􀂄 nlog(n) lower-bound for comparison-based sorting 􀂅 Parallel 􀂄 O(1), O(log(n)), O(???) Sorting networks 􀂅 Custom-made hardware for sorting! 􀂄 Hardware & algorithm

14 Elements of Sorting Networks:
Key Idea: 􀂅 Perform many comparisons in parallel. Key Elements: 􀂅 Comparators 􀂅 Network architecture

15 Comparators: Consist of two-input, two-output wires
Take two elements on the input wires and outputs them in sorted order in the output wires.

16 Comparators:

17 Network architecture:
The arrangement of the comparators into interconnected comparator columns.

18 Network architecture:

19 Sorting Networks: Many sorting networks have been developed.
Bitonic sorting network 􀄬(log2(n)) columns of comparators.

20 Bitonic Sequence: Bitonic sequences are graphically represented
by lines as follows:

21 Why Bitonic Sequences?

22 An example:

23 Bitonic Merging Network

24

25 Are we done? Given a set of elements, how do we re-arrange them into a bitonic sequence? Key Idea: Use successively larger bitonic networks to transform the set into a bitonic sequence.

26 Are we done?

27 An example:

28 Bitonic Sort on a Hypercube:
One-element-per-processor case How do we map the algorithm onto a hypercube? What is the comparator? How do the wires get mapped?

29 What can we say about the pairs of wires that are inputs to the various comparators?

30 Illustration

31 Communication Pattern:

32 Complexity Analyses: JAVA code
T(n) =T(n/2) + log(n) n= 2k Computational Complexity: O(log2(n))

33 Complexity Analyses: JAVA code (Cont.)


Download ppt "NEW SORTING ALGORITHMS"

Similar presentations


Ads by Google