Sorting Networks Lecture in E Freshman Seminar Series: Ten Puzzling Problems in omputer Engineering Ma 7 Sorting Networks Slide
bout This Presentation This presentation belongs to the lecture series entitled Ten Puzzling Problems in omputer Engineering, devised for a ten-week, one-unit, freshman seminar course b ehrooz Parhami, Professor of omputer Engineering at Universit of alifornia, Santa arbara The material can be used freel in teaching and other educational settings Unauthorized uses, including an use for financial gain, are prohibited ehrooz Parhami Edition Released Revised Revised First Ma 7 Ma 7 Sorting Networks Slide
Railroad Tracks and Switches Ma 7 Sorting Networks Slide
Railroad Yards Have Man Tracks and Switches Ma 7 Sorting Networks Slide
Rearranging Trains Train cars Engine Track D Sorted order D Stub or lead D Stub or lead D Stack or LIFO data structure in E Stub or lead D Question: Is there an ordering that cannot be sorted using a stub? nswer: Yes, if engine muse do the moving Sorting algorithm D Queue or FIFO Siding Ma 7 Sorting Networks Slide
Rearrangement with hange of Direction D Turnaround loop D D What tpes of sorting are possible with a turnaround loop? we? We onfiguration after the first few steps in sorting the train D omplete the sorting process, assuming that it is oka for the engine to end up behind the train Ma 7 Sorting Networks Slide 6
Delivering Train ars in a Specific Order ars in the train below have been sorted according to their deliver points However, it is still nontrivial to deposit car in stub, car in stub, and car in siding ars can be pulled or pushed b the engine D D Is there a better initial ordering of the cars for the deliveries in this puzzle? D Ma 7 Sorting Networks Slide 7
Train Passing Puzzle The trains below must pass each other using a siding that can hold onl one car or one engine Show how this can be done Ma 7 Sorting Networks Slide 8
Fast ombining or Reordering of Train ars D Forming multiple trains from incoming cars D Train reordering via a set of stubs ars are pushed or pulled b an engine lternativel, movement in one direction ma be achieved via sloped rails Switches used to be adjusted manuall, but nowadas, electronic control is used Ma 7 Sorting Networks Slide 9
Target track Sorting Train ars in Parallel Unconditional echange ompare-echange Track Track Track Track Track Track Track Track The net in stick diagram schematic Is adding this compare-echange element sufficient for producing a valid sorting network? Ma 7 Sorting Networks Slide
a b c d Validating a Sorting Network min(a, b) min(a, b, c, d) ma(a, b)???? min(c, d)???? ma(c, d) ma(a, b, c, d) Track Track Track Track In the eample above, it was fairl eas to show the validit of the sorting network Generall, it is much more difficult Stick diagram schematic How would one establish the validit of this 6-input sorting net? More importantl, how does one come up with this design in the first place? Ma 7 Sorting Networks Slide
Ma 7 Sorting Networks Slide The Zero-One Principle So, we can validate a sorting network using n rather than n! input patterns sorting net built of comparators is valid if it correctl sorts all - sequences n = : n = 96, n! = 79,,6 (thousands vs half a billion)
8 6 7 9 6-Input Sorting Network Use -input sorters, follow b (, )-mergers, and end with an (8, 8)-merger 8 6 7 9 6 7 8 9 Using the - principle, we can validate this network via 6 + + 8 tests 6 7 8 9 -sorter tests (, )-merger tests (8, 8)-merger tests Ma 7 Sorting Networks Slide
Ma 7 Sorting Networks Slide Insertion Sort and Selection Sort Fig 78 Sorting network based on insertion sort or selection sort (n )-sorter n n n n (n )-sorter n n n n Insertion sort Selection sort Parallel insertion sort = Parallel selection sort = Parallel bubble sort! (n) = n(n )/ D(n ) = n ost Dela = Θ(n ) Insertion sort Selection sort
The est Sorting Networks n = 6, modules, levels Which -input sorting network is better? n = 9, modules, 8 levels n =, 9 modules, 9 levels n =, modules, 7 levels ost = 9 Dela = 9 ost = Dela = 7 ost Dela = 9 9 = 6 ost Dela = 7 = 7 riterion : The number of sticks or compare-echange blocks (cost) riterion : The number of compare-echanges in sequence (dela) riterion : The product of cost and dela (cost-effectiveness) n =, modules, 8 levels The most cost-effective n-input sorting network ma be n = 6, 6 modules, 9 levels neither the fastest design, nor the lowest-cost design n = 6, 6 modules, levels Ma 7 Sorting Networks Slide
Electronic Sorting Networks Electronic sorting networks are built of -sorters, building blocks that can sort two inputs a min(a, b) b ma(a, b) pplications of sorting networks: Directing information packets to their destinations in a network router onnecting n processors to n memor modules in a parallel computer Ma 7 Sorting Networks Slide 6