Comparison Networks Sorting Sorting binary values

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

Gerth Stølting Brodal University of Aarhus Monday June 9, 2008, IT University of Copenhagen, Denmark International PhD School in Algorithms for Advanced.
22C:19 Discrete Structures Induction and Recursion Spring 2014 Sukumar Ghosh.
Batcher’s merging network Efficient Parallel Algorithms COMP308.
CSCE 3110 Data Structures & Algorithm Analysis
T(n) = 4 T(n/3) +  (n). T(n) = 2 T(n/2) +  (n)
1 Omega Network The omega network is another example of a banyan multistage interconnection network that can be used as a switch fabric The omega differs.
Advanced Topics in Algorithms and Data Structures Lecture 6.1 – pg 1 An overview of lecture 6 A parallel search algorithm A parallel merging algorithm.
Lecture 5: Linear Time Sorting Shang-Hua Teng. Sorting Input: Array A[1...n], of elements in arbitrary order; array size n Output: Array A[1...n] of the.
CS 253: Algorithms Chapter 8 Sorting in Linear Time Credit: Dr. George Bebis.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2001 Lecture 9 Tuesday, 11/20/01 Parallel Algorithms Chapters 28,
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (3) Recurrence Relation 11/11 ~ 11/14/2008 Yang Song.
Sorting networks Efficient Parallel Algorithms COMP308.
Advanced Topics in Algorithms and Data Structures Page 1 An overview of lecture 3 A simple parallel algorithm for computing parallel prefix. A parallel.
Bitonic and Merging sorting networks Efficient Parallel Algorithms COMP308.
Sorting Networks Uri Zwick Tel Aviv University May 2015.
Induction and recursion
Sorting in Linear Time Lower bound for comparison-based sorting
Parallel and Distributed Algorithms Eric Vidal Reference: R. Johnsonbaugh and M. Schaefer, Algorithms (International Edition) Pearson Education.
Design of Algorithms using Brute Force Approach. Primality Testing (given number is n binary digits)
Lecture 6 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
Comparison Networks Sorting Sorting binary values
Lecture 4 Sorting Networks. Comparator comparator.
Comparison Networks Sorting Sorting binary values Sorting arbitrary numbers Implementing symmetric functions.
1 Sorting Networks Sorting.
Lecture 6COMPSCI.220.FS.T Data Sorting Ordering relation: places each pair ,  of countable items in a fixed order denoted as (  ) or 
Section Recursion 2  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
Section Recursion  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
Sequences Lecture 11. L62 Sequences Sequences are a way of ordering lists of objects. Java arrays are a type of sequence of finite size. Usually, mathematical.
Lecture 2 Sorting.
CSE15 Discrete Mathematics 03/06/17
Lecture 4 Sorting Networks
The Design and Analysis of Algorithms
Sorting Networks Characteristics The basic unit: a comparator
7.1 What is a Sorting Network?
Divide-and-Conquer 6/30/2018 9:16 AM
CPSC 411 Design and Analysis of Algorithms
SORTING NETWORKS.
Introduction to Algorithms
The first Few Slides stolen from Boaz Barak
Chapter 5. Optimal Matchings
Growth Functions Algorithms Lecture 8
CS 3343: Analysis of Algorithms
Lecture 5 Algorithm Analysis
Linear Sorting Sections 10.4
Lecture 3 Induction Algorithm design techniques: induction
Lecture 5 Algorithm Analysis
Bucket-Sort and Radix-Sort
كلية المجتمع الخرج البرمجة - المستوى الثاني
Divide-and-Conquer 7 2  9 4   2   4   7
Bitonic and Merging sorting networks
Delta Network The delta network is one example of a multistage interconnection network that can be used as a switch fabric The delta network is an example.
Lecture 6 Algorithm Analysis
Building block to sort two numbers
Lecture 6 Algorithm Analysis
Lecture 43 Section 10.1 Wed, Apr 6, 2005
Linear-Time Sorting Algorithms
Time Complexity Lecture 14 Sec 10.4 Thu, Feb 22, 2007.
Lecture 5 Algorithm Analysis
Divide-and-Conquer 7 2  9 4   2   4   7
Time Complexity Lecture 15 Mon, Feb 27, 2006.
Algorithms CSCI 235, Spring 2019 Lecture 18 Linear Sorting
Advanced Analysis of Algorithms
Batcher Sorting Network, n = 4
CSCE 3110 Data Structures & Algorithm Analysis
CSCE 3110 Data Structures & Algorithm Analysis
Algorithms CSCI 235, Spring 2019 Lecture 19 Order Statistics
CSCE 3110 Data Structures & Algorithm Analysis
Efficient Parallel Algorithms COMP308
Lecture 5 Algorithm Analysis
Presentation transcript:

Comparison Networks Sorting Sorting binary values Sorting arbitrary numbers Implementing symmetric functions

Sorting Algorithms Example Mergesort(array[1,…,n] of Integers): begin Mergesort(array[1,…,n/2]); Mergesort(array[n/2+1,…,n]); Merge(array[1,…,n/2], array[n/2+1,…,n]); end comparisons required to merge two arrays of size m/2 comparisons to sort n elements Order of comparisons not fixed in advance. Not readily implementable in hardware.

Sorting Networks Sorting Network C D B A A B C D Order of comparisons fixed in advance. Readily implementable in hardware.

Sorting Networks (binary values) inputs outputs 1 sorted Sorting Network 1 1 1 1 1 1 1

Comparator (2-sorter) inputs outputs x min(x, y) C y max(x, y)

Comparator (2-sorter) AON Implementation x min(x, y) max(x, y) y inputs outputs x min(x, y) max(x, y) y

Comparator (2-sorter) inputs outputs x min(x, y) y max(x, y)

Comparison Network 1 1 1 1 width n depth d

Comparison Network 1 1 1 1 n / 2 comparisons per stage d stages

Sorting Network Any ideas?

Sorting Network inputs outputs Sorting Network . n . n 1

Insertion Sort Network inputs outputs depth 2n 3

Batcher Sorting Network Next Lecture

Sorting Arbitrary Numbers inputs outputs x min(x, y) y max(x, y) x, y can be values from any linearly ordered set, e.g., integers, reals, etc.

Integer Comparator X, Y: integers represented as m-bit binary strings. Comparison function: C(X,Y) = 1 if X > Y, 0 otherwise. Idea: use C(X,Y) to select the min and the max of X and Y.

Integer Comparator X C(X, Y) min(X, Y) Y C(X, Y) X C(X, Y) max(X, Y) Y

Sorting Arbitrary Numbers 9 6 2 2 9 6 6 9 2 2 6 9 sorted

Sorting Arbitrary Numbers 1 4 5 1 5 4 4 5 1 1 4 5 sorted

Sorting Arbitrary Numbers 3 7 3 7 7 3 3 7 not sorted How can we verify if a network sorts all possible input sequences?

Sorting Arbitrary Numbers inputs outputs Try all possible 0/1 sequences.

Sorting Arbitrary Numbers inputs outputs 000 000 Try all possible 0/1 sequences.

Sorting Arbitrary Numbers inputs outputs 1 1 1 1 000 000 001 001 Try all possible 0/1 sequences.

Sorting Arbitrary Numbers inputs outputs 1 1 1 1 000 000 001 001 010 001 Try all possible 0/1 sequences.

Sorting Arbitrary Numbers inputs outputs 1 1 1 1 000 000 001 001 010 001 011 011 Try all possible 0/1 sequences.

Sorting Arbitrary Numbers inputs outputs 1 1 1 1 000 000 001 001 010 001 011 011 100 001 Try all possible 0/1 sequences.

Sorting Arbitrary Numbers inputs outputs 1 1 1 1 000 000 001 001 010 001 011 011 100 001 101 011 Try all possible 0/1 sequences.

Sorting Arbitrary Numbers inputs outputs 1 1 1 1 000 000 001 001 010 001 011 011 100 001 101 011 110 101 not sorted! Try all possible 0/1 sequences.

Sorting Arbitrary Numbers inputs outputs 1 1 1 1 000 000 001 001 010 001 011 011 100 001 101 011 110 101 not sorted! 111 111 Try all possible 0/1 sequences.

Sorting Arbitrary Numbers

Sorting Arbitrary Numbers inputs outputs Try all possible 0/1 sequences.

Sorting Arbitrary Numbers inputs outputs 000 000 Try all possible 0/1 sequences.

Sorting Arbitrary Numbers inputs outputs 1 1 1 1 000 000 001 001 Try all possible 0/1 sequences.

Sorting Arbitrary Numbers inputs outputs 1 1 1 1 000 000 001 001 010 001 Try all possible 0/1 sequences.

Sorting Arbitrary Numbers inputs outputs 1 1 1 1 000 000 001 001 010 001 011 011 Try all possible 0/1 sequences.

Sorting Arbitrary Numbers inputs outputs 1 1 1 1 000 000 001 001 010 001 011 011 100 001 Try all possible 0/1 sequences.

Sorting Arbitrary Numbers inputs outputs 1 1 1 1 000 000 001 001 010 001 011 011 100 001 101 011 Try all possible 0/1 sequences.

Sorting Arbitrary Numbers inputs outputs 1 1 1 1 000 000 001 001 010 001 011 011 100 001 101 011 110 011 Try all possible 0/1 sequences.

Sorting Arbitrary Numbers inputs outputs 1 1 1 1 000 000 001 001 010 001 011 011 100 001 101 011 110 011 111 111 Try all possible 0/1 sequences.

Sorting Arbitrary Numbers inputs outputs 000 000 001 001 010 001 011 011 100 001 101 011 110 011 111 111 all sorted! Try all possible 0/1 sequences.

Zero-One Principle If a comparison network sorts all possible sequences of 0’s and 1’s correctly, then it sorts all sequences of arbitrary numbers correctly.

Lemma Given For a monotonically increasing function f,

Lemma Given For a monotonically increasing function f,

Proof: Lemma

Proof: Lemma

Proof: Lemma f is monotonically increasing:

Proof: Lemma f is monotonically increasing:

Proof: Lemma f is monotonically increasing:

Generalization Given

Generalization For a monotonically increasing function f, (by induction)

Proof: Zero-One Principle Suppose b) there exists a sequence that it doesn’t sort, i.e., such that but is placed before in the output. a) the network sorts all sequences of 0’s and 1’s, Define f (x) = 0 if 1 otherwise

Proof: Zero-One Principle Sorting Network .

Proof: Zero-One Principle . Sorting Network . . . .

Proof: Zero-One Principle . Sorting Network . . 1 contradiction! . .

Implementing XOR XOR(X) = 1 if odd 0 otherwise Sorting Network 1 1 1 1

Implementing XOR XOR(X) = 1 if odd 0 otherwise Sorting Network

Symmetric Functions for some subset of f (X) = 1 if 0 otherwise Sorting Network