Lecture 4 Sorting Networks Comparator comparator A Sorting

  • Slides: 42
Download presentation
Lecture 4 Sorting Networks

Lecture 4 Sorting Networks

Comparator comparator

Comparator comparator

A Sorting Network 9 5 2 2 5 9 6 5 2 2 5

A Sorting Network 9 5 2 2 5 9 6 5 2 2 5 6 6 6 9 9 A sorting network is a comparison network which output monotone nondecreasing sequence for every input.

Depth 9 5 2 2 5 9 6 5 2 2 5 6 6

Depth 9 5 2 2 5 9 6 5 2 2 5 6 6 6 9 9 Depth is the maximum number of comparators on a path from an input wire to an output wire.

Depth = parallel time 9 5 2 2 5 9 6 5 2 2

Depth = parallel time 9 5 2 2 5 9 6 5 2 2 5 6 6 6 9 9 Depth is the maximum number of comparators on a path from an input wire to an output wire.

Insertion Sort

Insertion Sort

key

key

Sorting network constructed from insertion sort.

Sorting network constructed from insertion sort.

How to construct a sorting network from merging sort?

How to construct a sorting network from merging sort?

Divide and Conquer • Divide the problem into subproblems. • Conquer the subproblems by

Divide and Conquer • Divide the problem into subproblems. • Conquer the subproblems by solving them recursively. • Combine the solutions to subproblems into the solution for original problem.

Merge Sort

Merge Sort

Procedure

Procedure

Structure Sorting network Merging network Sorting network

Structure Sorting network Merging network Sorting network

Construction of Merging Network • 0 -1 principal. • Bitonic sorter. • Merging network.

Construction of Merging Network • 0 -1 principal. • Bitonic sorter. • Merging network.

0 -1 principal

0 -1 principal

Lemma

Lemma

Proof of 0 -1 Principal

Proof of 0 -1 Principal

Bitonic Sequence

Bitonic Sequence

Bitonic 0 -1 Sequence

Bitonic 0 -1 Sequence

Some Properties

Some Properties

The half-cleaner bitonic 0 0 1 0 1 1 0 0 0 1 bitonic

The half-cleaner bitonic 0 0 1 0 1 1 0 0 0 1 bitonic clean bitonic

The half-cleaner bitonic 0 0 1 1 1 0 1 bitonic clean

The half-cleaner bitonic 0 0 1 1 1 0 1 bitonic clean

Lemma (a)One of two halfs is bitonic clean. (b) every number in the 1

Lemma (a)One of two halfs is bitonic clean. (b) every number in the 1 st half ≤ any element in the 2 nd half.

Proof (case 1) 0 0 0 1 0 1 0

Proof (case 1) 0 0 0 1 0 1 0

Proof (case 2) 0 0 1 0 0 0 1

Proof (case 2) 0 0 1 0 0 0 1

Proof (case 3) 0 0 0 1 1 1 0 0 1

Proof (case 3) 0 0 0 1 1 1 0 0 1

Proof (case 4) 0 0 0 1 1 0 0 0 1

Proof (case 4) 0 0 0 1 1 0 0 0 1

Proof (case 5) 1 0 1 0 1 1 1

Proof (case 5) 1 0 1 0 1 1 1

Proof (case 6) 1 1 0 1 0 1 1

Proof (case 6) 1 1 0 1 0 1 1

Proof (case 7) 0 1 1 0 0 1 1

Proof (case 7) 0 1 1 0 0 1 1

Proof (case 8) 0 1 1 0 1

Proof (case 8) 0 1 1 0 1

bitonic sorted Half cleaners

bitonic sorted Half cleaners

sorted 0 0 0 1 0 0 0 sorted 0 1 1 1 0

sorted 0 0 0 1 0 0 0 sorted 0 1 1 1 0 1 1 Half cleaners Merging Network

Structure Sorting network Merging network Sorting network

Structure Sorting network Merging network Sorting network

Sorting Network Merging Networks

Sorting Network Merging Networks

What we learnt in this lecture? • What is sorting network? • Depth =

What we learnt in this lecture? • What is sorting network? • Depth = parallel time. • Sorting network from Merge sort.

Permutation Network • Switching network • Rearrangeability • Nework with 2 x 2 crossbars

Permutation Network • Switching network • Rearrangeability • Nework with 2 x 2 crossbars

Crossbar Switch A crossbar switch can realize any matching between Inputs and outputs.

Crossbar Switch A crossbar switch can realize any matching between Inputs and outputs.

3 -stage Clos Network 1 n n m

3 -stage Clos Network 1 n n m

Rearrangeability Theorem

Rearrangeability Theorem

Network with 2 x 2 crossbars

Network with 2 x 2 crossbars

Puzzle

Puzzle