Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Comparison Networks Sorting Sorting binary values Sorting arbitrary numbers Implementing symmetric functions."— Presentation transcript:

1

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

3 Sorting Algorithms comparisons to sort n elements comparisons required to merge two arrays of size m/2 Order of comparisons not fixed in advance. 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 Not readily implementable in hardware. Example

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

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

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

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

8 Comparison Network 0 0 1 1 0 0 1 1 0 0 1 1 1 1 0 0 depth d width n

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

10 Sorting Network Any ideas?

11 Sorting Network inputs outputs n 1 Sorting Network...... n...

12 Insertion Sort Network inputs outputs depth 2n 3

13 Batcher Sorting Network Next Lecture

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

15 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. X, Y: integers represented as m-bit binary strings. Integer Comparator

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

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

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

19 Sorting Arbitrary Numbers inputsoutputs Try all possible 0/1 sequences.

20 Sorting Arbitrary Numbers 0 0 0 0 0 0 0 0 0 0 0 0 000 inputsoutputs Try all possible 0/1 sequences.

21 Sorting Arbitrary Numbers 0 1 0 0 0 1 0 0 1 0 1 0 inputsoutputs 000 Try all possible 0/1 sequences. 001

22 Sorting Arbitrary Numbers 0 0 1 0 0 1 0 1 0 0 1 0 inputsoutputs 000 Try all possible 0/1 sequences. 001 010 001

23 Sorting Arbitrary Numbers 0 1 1 0 1 1 0 1 1 1 1 0 inputsoutputs 000 Try all possible 0/1 sequences. 001 010001 011

24 Sorting Arbitrary Numbers 1 0 0 0 0 1 0 1 0 0 1 0 inputsoutputs 000 Try all possible 0/1 sequences. 001 010001 011 100 001

25 Sorting Arbitrary Numbers 1 1 0 0 1 1 0 1 1 1 1 0 inputsoutputs 000 Try all possible 0/1 sequences. 001 010001 011 100001 101 011

26 Sorting Arbitrary Numbers 1 0 1 1 0 1 1 1 0 0 1 1 inputsoutputs 000 Try all possible 0/1 sequences. 001 010001 011 100001 101011 110 101 not sorted!

27 Sorting Arbitrary Numbers 1 1 1 1 1 1 1 1 1 1 1 1 inputsoutputs 000 Try all possible 0/1 sequences. 001 010001 011 100001 101011 110101 111 not sorted!

28 Sorting Arbitrary Numbers

29 inputsoutputs Try all possible 0/1 sequences.

30 Sorting Arbitrary Numbers 0 0 0 0 0 0 0 0 0 0 0 0 000 inputsoutputs Try all possible 0/1 sequences.

31 Sorting Arbitrary Numbers 0 1 0 0 0 1 0 0 1 0 1 0 inputsoutputs 000 Try all possible 0/1 sequences. 001

32 Sorting Arbitrary Numbers 0 0 1 0 0 1 0 1 0 1 0 0 inputsoutputs 000 Try all possible 0/1 sequences. 001 010 001

33 Sorting Arbitrary Numbers 0 1 1 0 1 1 0 1 1 1 1 0 inputsoutputs 000 Try all possible 0/1 sequences. 001 010001 011

34 Sorting Arbitrary Numbers 1 0 0 0 0 1 0 1 0 1 0 0 inputsoutputs 000 Try all possible 0/1 sequences. 001 010001 011 100 001

35 Sorting Arbitrary Numbers 1 1 0 0 1 1 0 1 1 1 1 0 inputsoutputs 000 Try all possible 0/1 sequences. 001 010001 011 100001 101 011

36 Sorting Arbitrary Numbers 1 0 1 0 1 1 1 1 0 1 1 0 inputsoutputs 000 Try all possible 0/1 sequences. 001 010001 011 100001 101011 110 011

37 Sorting Arbitrary Numbers 1 1 1 1 1 1 1 1 1 1 1 1 inputsoutputs 000 Try all possible 0/1 sequences. 001 010001 011 100001 101011 110011 111

38 Sorting Arbitrary Numbers inputsoutputs 000 Try all possible 0/1 sequences. 001 010001 011 100001 101011 110011 111 all sorted!

39 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.

40 Lemma Given For a monotonically increasing function f,

41 Lemma Given For a monotonically increasing function f,

42 Proof: Lemma

43

44 f is monotonically increasing:

45 Proof: Lemma f is monotonically increasing:

46 Proof: Lemma f is monotonically increasing:

47 Generalization Given

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

49 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

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

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

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


Download ppt "Comparison Networks Sorting Sorting binary values Sorting arbitrary numbers Implementing symmetric functions."

Similar presentations


Ads by Google