Lecture 6 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.

Slides:



Advertisements
Similar presentations
Lecture 24 MAS 714 Hartmut Klauck
Advertisements

Batcher’s merging network Efficient Parallel Algorithms COMP308.
© The McGraw-Hill Companies, Inc., Chapter 2 The Complexity of Algorithms and the Lower Bounds of Problems.
Heiko Schröder, 2003 Parallel Architectures 1 Various communication networks State of the art technology Important aspects of routing schemes Known results.
Parallel Prefix Computation Advanced Algorithms & Data Structures Lecture Theme 14 Prof. Dr. Th. Ottmann Summer Semester 2006.
The main idea of the article is to prove that there exist a tester of monotonicity with query and time complexity.
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.
2 -1 Chapter 2 The Complexity of Algorithms and the Lower Bounds of Problems.
UMass Lowell Computer Science Analysis of Algorithms Prof. Karen Daniels Fall, 2001 Lecture 9 Tuesday, 11/20/01 Parallel Algorithms Chapters 28,
2 -1 Analysis of algorithms Best case: easiest Worst case Average case: hardest.
CS 584. Sorting n One of the most common operations n Definition: –Arrange an unordered collection of elements into a monotonically increasing or decreasing.
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.
MergeSort Source: Gibbs & Tamassia. 2 MergeSort MergeSort is a divide and conquer method of sorting.
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.
Lecture 12: Parallel Sorting Shantanu Dutt ECE Dept. UIC.
1 Parallel Sorting Algorithms. 2 Potential Speedup O(nlogn) optimal sequential sorting algorithm Best we can expect based upon a sequential sorting algorithm.
A Simple Algorithm for Stable Minimum Storage Merging Pok-Son Kim Kookmin University, Department of Mathematics, Seoul , Korea Arne Kutzner Seokyeong.
Parallel and Distributed Algorithms Eric Vidal Reference: R. Johnsonbaugh and M. Schaefer, Algorithms (International Edition) Pearson Education.
Lecture 2 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
Design of Algorithms using Brute Force Approach. Primality Testing (given number is n binary digits)
Comparison Networks Sorting Sorting binary values
Lecture 9 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
Lecture 11 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
Algorithms 1.Notion of an algorithm 2.Properties of an algorithm 3.The GCD algorithm 4.Correctness of the GCD algorithm 5.Termination of the GCD algorithm.
Lecture 4 Sorting Networks. Comparator comparator.
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.
“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.
Young CS 331 D&A of Algo. Topic: Divide and Conquer1 Divide-and-Conquer General idea: Divide a problem into subprograms of the same kind; solve subprograms.
Lecture 2 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
1 Sorting Networks Sorting.
Sorting: Parallel Compare Exchange Operation A parallel compare-exchange operation. Processes P i and P j send their elements to each other. Process P.
Lecture 5 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
Lecture 12 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea.
Sorting by placement and Shift Sergi Elizalde Peter Winkler By 資工四 B 周于荃.
Lecture 2 Algorithm Analysis
Lecture 4 Sorting Networks
Sorting Networks Characteristics The basic unit: a comparator
Unit 1. Sorting and Divide and Conquer
SORTING NETWORKS.
Heaps © 2010 Goodrich, Tamassia Heaps Heaps
Lecture 12 Algorithm Analysis
Lecture 7 Algorithm Analysis
MergeSort Source: Gibbs & Tamassia.
Lecture 5 Algorithm Analysis
Lecture 10 Algorithm Analysis
Rank Aggregation.
Enumerating Distances Using Spanners of Bounded Degree
Bitonic Sorting and Its Circuit Design
Lecture 5 Algorithm Analysis
Comparison Networks Sorting Sorting binary values
Topic: Divide and Conquer
Richard Anderson Lecture 13 Divide and Conquer
Lecture 7 Algorithm Analysis
Lecture 12 Algorithm Analysis
Bitonic and Merging sorting networks
Lecture 6 Algorithm Analysis
Lecture 6 Algorithm Analysis
Lecture 7 Algorithm Analysis
Lecture 5 Algorithm Analysis
Lecture 12 Algorithm Analysis
Parallel Sorting Algorithms
Efficient Parallel Algorithms COMP308
Lecture 5 Algorithm Analysis
Presentation transcript:

Lecture 6 Algorithm Analysis Arne Kutzner Hanyang University / Seoul Korea

Sorting Networks

2014/10Algorithm AnalysisL6.3L6.3 Sorting Networks Example of Parallel Algorithms Not directly related to our classical “computer models” (e.g. Turing machines, von-Neumann architecture)

2014/10Algorithm AnalysisL6.4L6.4 Comparator Works in O(1) time. Input wires Output wires wire

2014/10Algorithm AnalysisL6.5L6.5 Example of Comparison Network Wires go straight, left to right. Each comparator has inputs/outputs on some pair of wires. Input Output

2014/10Algorithm AnalysisL6.6L6.6 Correctness of Example Network Claim that this comparison network will sort any set of 4 input values: –After leftmost comparators, minimum is on either wire 1 (from top) or 3, maximum is on either wire 2 or 4. –After next 2 comparators, minimum is on wire 1, maximum on wire 4. –Last comparator gets correct values onto wires 2 and 3.

2014/10Algorithm AnalysisL6.7L6.7 Definition of Depth Depth of some Wire: Input wires of the network have depth 0 Depth of a comparator := depth of its output wire Depth of a Network := maximum depth of a an output wire of the network Input depth: d x Input depth: d y Output depth: max (d x,d y ) + 1

2014/10Algorithm AnalysisL6.8L6.8 Depth - Example Depth 1Depth 2Depth 3

2014/10Algorithm AnalysisL6.9L6.9 Selection Sorter Foundation: Bouble-Sort Idea Find the maximum of 5 values:

2014/10Algorithm AnalysisL6.10 Selection Sorter (cont.) We extend our idea: Depth: Selection Sorter for 4 elements

2014/10Algorithm AnalysisL6.11 Zero-one principle How can we test if a comparison network sorts? –We could try all n! permutations of input. –But we will see that we need to test only 2 n permutations. Theorem (0-1 principle) If a comparison network with n inputs sorts all 2 n sequences of 0.s and 1.s, then it sorts all sequences of arbitrary numbers.

2014/10Algorithm AnalysisL6.12 Important Lemma Lemma: If a comparison network transforms a = into b =, then for any monotonically increasing function f, it transforms f(a) = into f(b) =.

2014/10Algorithm AnalysisL6.13 Proof of Lemma Important property: Then use induction on the depth of some wire

2014/10Algorithm AnalysisL6.14 Proof of 0-1 principle Suppose that the principle is not true, so that an n-input comparison network sorts all 0-1 sequences, but there is a sequence such that a i < a j but a i comes after a j in the output. Define the monotonically increasing function

2014/10Algorithm AnalysisL6.15 Proof 0-1 principle (cont.) By our lemma proven before: If we give the input, then in the output we will have f(a i ) after f(a j ) But this results in an unsorted 0-1 sequence. A contradiction.

2014/10Algorithm AnalysisL6.16 Definition of the notion “bitonic” A sequence is bitonic if it monotonically increases, then monotonically decreases, or it can be circularly shifted to become so. Examples:,, For 0-1 sequences bitonic sequences have the form:

2014/10Algorithm AnalysisL6.17 Half Cleaner Comparison network of depth 1 in which input of line i is compared with line i+n/2 for i=1,2,…,n/2

2014/10Algorithm AnalysisL6.18 Property of Half Cleaner Lemma: If the input to a half-cleaner is a bitonic 0-1 sequence, then for the output: –both the top and bottom half are bitonic, –every element in the top half is ≤ every element in the bottom half, and –at least one of the halves is clean.all 0.s or all 1.s. Proof: Simple inspection of 8 different cases.

2014/10Algorithm AnalysisL6.19 Bitonic Sorter Recursively defined, so we have:

2014/10Algorithm AnalysisL6.20 Example for bitonic Sorter

2014/10Algorithm AnalysisL6.21 Merging Network Idea: Given 2 sorted sequences, reverse the second one, then concatenate with the first one ⇒ get a bitonic sequence. Example: X = 0011 Y = 0111 Y R = 1110 XY R = (bitonic)

2014/10Algorithm AnalysisL6.22 Merging Network (cont.) How do we reverse Y? We don’t! Instead, we reverse the bottom half of the connections of the first half-cleaner: X YRYR Y is equal to X Y

2014/10Algorithm AnalysisL6.23 Merging Network - Example So we get as Merging Network:

2014/10Algorithm AnalysisL6.24 Sorting Network – Construction Principle Using the MergeSort-Idea we can recursively construct a Sorting Network by combining several Merger

2014/10Algorithm AnalysisL6.25 Sorting Network - Example Example: n = 8 Sorter

2014/10Algorithm AnalysisL6.26 Sorting Network – Example (cont.) Merger

2014/10Algorithm AnalysisL6.27 Sorting Network – Complexity Analysis According to the construction principle for sorting networks we get: