+ Even Odd Sort & Even-Odd Merge Sort Wolfie Herwald Pengfei Wang Rachel Celestine.

Slides:



Advertisements
Similar presentations
CS 400/600 – Data Structures External Sorting.
Advertisements

Garfield AP Computer Science
Heaps1 Part-D2 Heaps Heaps2 Recall Priority Queue ADT (§ 7.1.3) A priority queue stores a collection of entries Each entry is a pair (key, value)
Batcher’s merging network Efficient Parallel Algorithms COMP308.
Practice Quiz Question
Sorting A fundamental operation in computer science (many programs need to sort as an intermediate step). Many sorting algorithms have been developed Choose.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 9A Sorting (Concepts)
Visual C++ Programming: Concepts and Projects
Quick Sort, Shell Sort, Counting Sort, Radix Sort AND Bucket Sort
CSCE 3110 Data Structures & Algorithm Analysis
1 Potential for Parallel Computation Module 2. 2 Potential for Parallelism Much trivially parallel computing  Independent data, accounts  Nothing to.
Parallel Sorting Algorithms Comparison Sorts if (A>B) { temp=A; A=B; B=temp; } Potential Speed-up –Optimal Comparison Sort: O(N lg N) –Optimal Parallel.
1 Sorting/Searching CS308 Data Structures. 2 Sorting means... l Sorting rearranges the elements into either ascending or descending order within the array.
Chapter 11 Sorting and Searching. Copyright © 2005 Pearson Addison-Wesley. All rights reserved Chapter Objectives Examine the linear search and.
Sorting Algorithms CS 524 – High-Performance Computing.
1 Lecture 25: Parallel Algorithms II Topics: matrix, graph, and sort algorithms Tuesday presentations:  Each group: 10 minutes  Describe the problem,
CHAPTER 11 Sorting.
Sorting Algorithms: Topic Overview
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (3) Recurrence Relation 11/11 ~ 11/14/2008 Yang Song.
1 Parallel Algorithms III Topics: graph and sort algorithms.
Sorting Algorithms Ananth Grama, Anshul Gupta, George Karypis, and Vipin Kumar To accompany the text ``Introduction to Parallel Computing'', Addison Wesley,
Bitonic and Merging sorting networks Efficient Parallel Algorithms COMP308.
CSCI-455/552 Introduction to High Performance Computing Lecture 22.
CS 202, Spring 2003 Fundamental Structures of Computer Science II Bilkent University1 Sorting CS 202 – Fundamental Structures of Computer Science II Bilkent.
© 2006 Pearson Addison-Wesley. All rights reserved10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
Sorting and Searching Arrays CSC 1401: Introduction to Programming with Java Week 12 – Lectures 1 & 2 Wanda M. Kunkle.
1 Sorting Algorithms - Rearranging a list of numbers into increasing (strictly non-decreasing) order. ITCS4145/5145, Parallel Programming B. Wilkinson.
1 Data Structures and Algorithms Sorting. 2  Sorting is the process of arranging a list of items into a particular order  There must be some value on.
1 Parallel Sorting Algorithms. 2 Potential Speedup O(nlogn) optimal sequential sorting algorithm Best we can expect based upon a sequential sorting algorithm.
CALTECH CS137 Winter DeHon 1 CS137: Electronic Design Automation Day 12: February 6, 2006 Sorting.
CHAPTER 09 Compiled by: Dr. Mohammad Omar Alhawarat Sorting & Searching.
Fall 2013 Instructor: Reza Entezari-Maleki Sharif University of Technology 1 Fundamentals of Programming Session 17 These.
Simple Iterative Sorting Sorting as a means to study data structures and algorithms Historical notes Swapping records Swapping pointers to records Description,
Sorting CS 110: Data Structures and Algorithms First Semester,
Fundamentals of Algorithms MCS - 2 Lecture # 15. Bubble Sort.
1 C++ Plus Data Structures Nell Dale Chapter 10 Sorting and Searching Algorithms Slides by Sylvia Sorkin, Community College of Baltimore County - Essex.
Searching and Sorting Recursion, Merge-sort, Divide & Conquer, Bucket sort, Radix sort Lecture 5.
Sorting CS Sorting means... Sorting rearranges the elements into either ascending or descending order within the array. (we’ll use ascending order.)
Sorting and Searching. Selection Sort  “Search-and-Swap” algorithm 1) Find the smallest element in the array and exchange it with a[0], the first element.
Chapter 8 Sorting and Searching Goals: 1.Java implementation of sorting algorithms 2.Selection and Insertion Sorts 3.Recursive Sorts: Mergesort and Quicksort.
Review 1 Selection Sort Selection Sort Algorithm Time Complexity Best case Average case Worst case Examples.
Lecture No. 04,05 Sorting.  A process that organizes a collection of data into either ascending or descending order.  Can be used as a first step for.
1 Searching and Sorting Searching algorithms with simple arrays Sorting algorithms with simple arrays –Selection Sort –Insertion Sort –Bubble Sort –Quick.
1 Parallel Sorting Algorithm. 2 Bitonic Sequence A bitonic sequence is defined as a list with no more than one LOCAL MAXIMUM and no more than one LOCAL.
Ananth Grama, Anshul Gupta, George Karypis, and Vipin Kumar
Elementary Sorting 30 January Simple Sort // List is an array of size == n for (i = 1; i < n; i++) for (j = i+1; j List[j])
ICS201 Lecture 21 : Sorting King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science Department.
PREVIOUS SORTING ALGORITHMS  BUBBLE SORT –Time Complexity: O(n 2 ) For each item, make (n –1) comparisons Gives: Comparisons = (n –1) + (n – 2)
Sorting 9/13/2010. Introduction In CS1 you covered Insertion Sort, Bubble Sort, and Selection Sort. – In these algorithms we end up making a significant.
Review Quick Sort Quick Sort Algorithm Time Complexity Examples
Sorting & Searching Geletaw S (MSC, MCITP). Objectives At the end of this session the students should be able to: – Design and implement the following.
Unit-8 Sorting Algorithms Prepared By:-H.M.PATEL.
 2006 Pearson Education, Inc. All rights reserved. 1 Searching and Sorting.
CSCI-455/552 Introduction to High Performance Computing Lecture 21.
Data Structures and Algorithms Instructor: Tesfaye Guta [M.Sc.] Haramaya University.
Sorting and Runtime Complexity CS255. Sorting Different ways to sort: –Bubble –Exchange –Insertion –Merge –Quick –more…
Sort Algorithm.
3.3 Fundamentals of data representation
Searching and Sorting Algorithms
Warmup What is an abstract class?
Adapted from slides by Marty Stepp and Stuart Reges
Bubble Sort Bubble sort is one way to sort an array of numbers. Adjacent values are swapped until the array is completely sorted. This algorithm gets its.
Adapted from slides by Marty Stepp and Stuart Reges
Adapted from slides by Marty Stepp and Stuart Reges
Advanced Sorting Methods: Shellsort
Bitonic and Merging sorting networks
Parallel sorting.
Parallel Sorting Algorithms
Core Assessments Core #1: This Friday (5/4) Core #2: Tuesday, 5/8.
Presentation transcript:

+ Even Odd Sort & Even-Odd Merge Sort Wolfie Herwald Pengfei Wang Rachel Celestine

+ Simple algorithm developed originally for use on parallel processors with local interconnections. The algorithm was originally presented, and shown to be efficient on parallel processors, by Habermann in On a parallel processors, with one value per processor and only left-right neighbor connections, the processors all concurrently do a compare-exchange operation with their neighbors, alternating between odd-even and even-odd pairings,

+ How it Works 1. Comparing all odd or all even indexed pairs of adjacent elements in the list If the first value is larger than the second value then we swap them (similar to bubble sort) 2. The next step repeats this for all even or all odd indexed pairs and continues to alternate until the list is sorted

+ Example

+ Best Case: O(n) Worst Case: O(n 2 )

+

+ Odd Even Merge Sort Odd-Even MergeSort was developed by Ken Batcher A related but more efficient algorithm, that uses compare- exchange and perfect shuffle operations It is based on a merge algorithm that merges two sorted halves of a sequence to a completely sorted sequence. In contrast to mergesort, this algorithm is not data-dependent meaning that same comparisons are performed regardless of the actual data. Because of this odd-even mergesort can be implemented as a sorting network

+ Visual Representation

+ Theorem For any list of length n, where n is a multiple of 4, first sorting separately the first and second halves, then sorting separately the odd-indexed keys and the even-indexed keys, and finally comparing-and-switching the keys indexed 2` and 2` + 1 for ` = 1, 2, · · ·,(n/2) − 1 results in a sorted list. Proof. After the two halves of the list have been sorted separately, it is obvious that for all i between 1 and n except for 1 and n 2 + 1, the (i − 1)-st element of the list is less than the i-th. Call the (i − 1)-st key the predecessor of the i-th. Note that 1 and n/2 + 1 are both odd. Every even-indexed key has as its predecessor a number smaller than itself (since any even-indexed key and its predecessor are in the same half), so the `-th smallest even-indexed key must be larger than at least ` odd-indexed keys (look at its predecessor as well as the predecessors of the ` − 1 even-indexed keys that are smaller than it). Similarly, every odd-indexed key (with the possible exception of two keys, namely the 1st and (n 2 + 1)-st) has as its predecessor a number smaller than itself, so the `+ 1-st smallest odd-indexed key must be larger than at least ` − 1 even-indexed keys. If we denote by ki the i-th indexed key after sorting the first and second halves and the even and odd halves, we have just argued that k2` − 1 ≤ k2` and k2` − 2 ≤ k2`+1, for any appropriate `. Since we have sorted the even indexed keys and the odd indexed keys, we also know that k2` − 2 ≤ k2` and that k2` − 1 ≤ k2`+1. Thus, if we group the elements in pairs (k2`, k2`+1) for each appropriate `, we see that both elements of a pair are greater or equal to both elements of the previous pair. To finish the sort after sorting the odds and evens, it is therefore only necessary to compare the ` + 1-st smallest odd-indexed key (k2`+1) to the `-th smallest even-indexed key (k2`) for each appropriate ` to determine its rank completely; this is precisely what the final step does.

+ Psuedo Code OddEvenMergeSort(list) Input: sequence of a o ……a n-1 whose 2 halves of a o ……a n/2-1 and of a n/2 ……a n-1 are sorted Method: if n>2 then 1. apply odd-even mergesort(n/2) to a o, a 2, …, a n-2 and a 1, a 3, …, a n-1 2. perform odd-even merge(n) 3. for i = {1, 3, …, n-3} if a i > a i+1 swap [a i, a i+1 ] else if a 0 > a 1 swap [a 0, a 1 ] Output: the sorted sequence

+ Example Original array: 3,30,1,6,2,10,20,9,15,8,21,7

+ Best/Worst Case Performance: O(log 2 (n)) Significantly more efficient then merge sort of quick sort: Average/Worst Case Performance O(nlog 2 (n)) Best Case Performance O(n)/O(nlog 2 (n)) (With Parallel Processing)

+ Odd Even Merge Sort Video