Sorting Networks Characteristics The basic unit: a comparator

Slides:



Advertisements
Similar presentations
II Extreme Models Study the two extremes of parallel computation models: Abstract SM (PRAM); ignores implementation issues Concrete circuit model; incorporates.
Advertisements

Walks, Paths and Circuits Walks, Paths and Circuits Sanjay Jain, Lecturer, School of Computing.
Analysis of Algorithms CS 477/677 Linear Sorting Instructor: George Bebis ( Chapter 8 )
Batcher’s merging network Efficient Parallel Algorithms COMP308.
CSCE 3110 Data Structures & Algorithm Analysis
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 Tuesday, November 14, 2006 “UNIX was never designed to keep people from doing stupid things, because that policy would also keep them from doing clever.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2001 Lecture 9 Tuesday, 11/20/01 Parallel Algorithms Chapters 28,
1 Parallel Algorithms III Topics: graph and sort algorithms.
Sorting networks Efficient Parallel Algorithms COMP308.
Analysis of Algorithms CS 477/677
Bitonic and Merging sorting networks Efficient Parallel Algorithms COMP308.
Sorting Networks Uri Zwick Tel Aviv University May 2015.
Cardinality & Sorting Networks. Cardinality constraint Appears in many practical problems: scheduling, timetabling etc’. Also takes place in the Max-Sat.
Unit 1. Sorting and Divide and Conquer. Lecture 1 Introduction to Algorithm and Sorting.
Computer Algorithms Lecture 11 Sorting in Linear Time Ch. 8
Lecture 2 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
Lecture 6 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
Analysis of Algorithms CS 477/677
Comparison Networks Sorting Sorting binary values
Lecture 4 Sorting Networks. Comparator comparator.
“Sorting networks and their applications”, AFIPS Proc. of 1968 Spring Joint Computer Conference, Vol. 32, pp
Comparison Networks Sorting Sorting binary values Sorting arbitrary numbers Implementing symmetric functions.
Ananth Grama, Anshul Gupta, George Karypis, and Vipin Kumar
Sorting. Sorting Sorting is important! Things that would be much more difficult without sorting: –finding a telephone number –looking up a word in the.
1 Sorting Networks Sorting.
Selection Sort Given an array[0-N], place the smallest item in the array in position 0, the second smallest in position 1, and so forth. We do thisby comparing.
Chapter 4, Part II Sorting Algorithms. 2 Heap Details A heap is a tree structure where for each subtree the value stored at the root is larger than all.
Parallel Programming - Sorting David Monismith CS599 Notes are primarily based upon Introduction to Parallel Programming, Second Edition by Grama, Gupta,
Unit-8 Sorting Algorithms Prepared By:-H.M.PATEL.
Sorting: Parallel Compare Exchange Operation A parallel compare-exchange operation. Processes P i and P j send their elements to each other. Process P.
Sorting by placement and Shift Sergi Elizalde Peter Winkler By 資工四 B 周于荃.
Recurrences It continues… Jeff Chastine. Recurrences When an algorithm calls itself recursively, its running time is described by a recurrence. A recurrence.
(Proof By) Induction Recursion
Prof. U V THETE Dept. of Computer Science YMA
Lecture 2 Algorithm Analysis
Lecture 4 Sorting Networks
Modeling with Recurrence Relations
An Iterative FFT We rewrite the loop to calculate nkyk[1] once
7.1 What is a Sorting Network?
Unit 1. Sorting and Divide and Conquer
CS 3343: Analysis of Algorithms
SORTING NETWORKS.
Mergesort CSE 2320 – Algorithms and Data Structures Vassilis Athitsos
Introduction to Algorithms
COSC160: Data Structures Linked Lists
Algorithm Analysis CSE 2011 Winter September 2018.
More on Merge Sort CS 244 This presentation is not given in class
CS 3343: Analysis of Algorithms
CS 154, Lecture 4: Limitations on DFAs (I),
Enumerating Distances Using Spanners of Bounded Degree
Lecture 7 All-Pairs Shortest Paths
Bitonic Sorting and Its Circuit Design
Comparison Networks Sorting Sorting binary values
Data Structures Review Session
Divide-and-Conquer 7 2  9 4   2   4   7
Bitonic and Merging sorting networks
CS200: Algorithms Analysis
Lecture 6 Algorithm Analysis
Copyright © Cengage Learning. All rights reserved.
Lecture 6 Algorithm Analysis
Basics of Recursion Programming with Recursion
Linear-Time Sorting Algorithms
Lecture 5 Algorithm Analysis
Divide-and-Conquer 7 2  9 4   2   4   7
Solving recurrence equations
Divide-and-Conquer 7 2  9 4   2   4   7
Discrete Mathematics CS 2610
Divide and Conquer Merge sort and quick sort Binary search
Efficient Parallel Algorithms COMP308
Presentation transcript:

Sorting Networks Characteristics The basic unit: a comparator Implemented in hardware Parallel operations are possible The basic unit: a comparator Comparison occurs when both inputs are available Comparison time is O(1) A comparator sorts two inputs

A Comparison Network Characteristics: four inputs, four outputs, five comparators, depth of three This comparison network is a sorter; how can this be explained in common sense terms?

Some Thought Problems Why must any sorting network with n inputs have at least a depth of lg n ? Why must a sorting network with n inputs perform at least n lg n comparisons ?

A Sorting Network Based on Insertion Sort Explain why this is based on insertion sort General characteristics for an n input network What will be the depth of the network? How many comparators are there in the network?

The Zero-One Principle - 1 The basic idea is that is you can prove an n input comparison network sorts the 2n inputs with 0 or 1 correctly then it will sort any data correctly The proof of the lemma has two basic steps Induction is then used to prove the lemma

The Zero-One Principle - 2 Induction is based on the depth of the network The result for depth zero is trivial For depth d, it is proved for depth d+1 using the result on the previous page The outputs are at a specific depth, so it is true at the outputs too An example with f =  x/2 

The Zero-One Principle - 3

A Bitonic Sorting Network What is a bitonic sequence? A sequence that increases then decreases, such as { 3, 5, 7, 9, 12, 14, 11, 8, 7, 4, 2 } or such a sequence that has been circularly shifted For inputs of 0 and 1, a bitonic sequence has one of two forms: 0i1j0k or 1i0j1k Steps in the process Build a “half-cleanser” network Build a bitonic sorter recursively by halving the size from n to n/2 to n/4 until a base case of 2 is reached Show the computation time is lg n

A Half-Cleaner A half-cleaner with bitonic input produces one of two possible outputs

Proof of Lemma - 1 Assume inputs of the form 0i1j0k ; there are four cases, two are shown here

Proof of Lemma - 2 The other two cases There is a symmetric proof for inputs of the form 1i0j1k

Building the Bitonic Sorter Steps A half-cleanser of size n is introduced Two parallel bitonic sorters of size n/2 are attached A recursive unraveling continues until the base case is reached The final circuit is a bitonic sorter of size n

Depth of the Sorter This result has been shown for a zero-one bitonic sorter In a manner analogous to the zero-one theorem, it can be shown this same network can sort bitonic sequences of any arbitrary numbers

The First Stage of a Merger An intuitive approach Given two sorted sequences X and Y; reverse the Y to give YR, the concatenated sequence X YR is bitonic Perform a bitonic sort on the sequence X YR The first stage of the merger compares input i with input n-i+1 Comparing Merger[n] and Half-Cleanser[n] shows that the outputs of the bottom of the first stage are reversed

A Merging Network The merging network is completed by attaching bitonic sorters to the outputs of the first stage An 8 input merger is shown below where two sorted sequences of length four are merged into a sorted sequence of length eight

A Sorting Network The sorting network is produced by unwinding the mergers from right to left

The Depth of Sorter[n] Calculating the depth recursively The depth of sorter[n] is the depth of sorter[n/2] plus the depth of the merger[n], which is lg n Note the the two sorter[n/2] run in parallel so it only appears once in the recurrence relation

An Odd-Even Transposition Sorter An odd-even transposition sorter is based on a bubble sort algorithm Here is the sorter for eight inputs

Name(s)______________________________ Use the zero-one principle to prove the this comparison network is a sorting network

Name(s)______________________________ How many bitonic sequences containing 0 or 1 are there? Prove a bitonic sorter of size n, a power of 2, contains exactly ( n lg n) comparators

Name(s)______________________________ Design a network that merges 1 item with n-1 sorted items to produce n sorted items Show that to produce a sequence of length n, the merger must have a depth of at least lg n

Name(s)______________________________ How many comparators are needed to build sorter[n] ? (assume n is a power of 2) Prove the depth of sorter[n] is exactly (lg n) (lg n + 1)/2

Name(s)______________________________ How many comparators are needed to build odd-even[n] ? (assume n is a power of 2) What is the depth of odd-even[n] ?

Name(s)______________________________ How many comparators are needed to build insertion_sorter[n] ? (assume n is a power of 2) What is the depth of insertion_sorter[n] ?