Sorting Networks A Lecture in CE Freshman Seminar Series:

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

Physics for Scientists and Engineers, 6e
Apr. 2007SatisfiabilitySlide 1 Satisfiability A Lecture in CE Freshman Seminar Series: Ten Puzzling Problems in Computer Engineering.
Chapter 3: The Efficiency of Algorithms Invitation to Computer Science, Java Version, Third Edition.
Nov. 2005Math in ComputersSlide 1 Math in Computers A Lesson in the “Math + Fun!” Series.
Traffic Flow Analysis Steve Prevette Burnt Hills & Big Flats RR Pasco WA Fluor Hanford City University.
Mar. 2005Measurement PuzzlesSlide 1 Measurement Puzzles A Lesson in the “Math + Fun!” Series.
Apr. 2007Mathematical IllusionsSlide 1 Mathematical Illusions A Lesson in the “Math + Fun!” Series.
May 2015Binary SearchSlide 1 Binary Search A Lecture in CE Freshman Seminar Series: Ten Puzzling Problems in Computer Engineering.
May 2007Task SchedulingSlide 1 Task Scheduling A Lecture in CE Freshman Seminar Series: Ten Puzzling Problems in Computer Engineering.
Apr. 2015SatisfiabilitySlide 1 Satisfiability A Lecture in CE Freshman Seminar Series: Ten Puzzling Problems in Computer Engineering.
June 2007Malfunction DiagnosisSlide 1 Malfunction Diagnosis A Lecture in CE Freshman Seminar Series: Ten Puzzling Problems in Computer Engineering.
Mar. 2006Measuring InstrumentsSlide 1 Measuring Instruments A Lesson in the “Math + Fun!” Series.
Apr. 2007Placement and RoutingSlide 1 Placement and Routing A Lecture in CE Freshman Seminar Series: Ten Puzzling Problems in Computer Engineering.
Mar. 2015Easy, Hard, Impossible!Slide 1 Easy, Hard, Impossible! A Lecture in CE Freshman Seminar Series: Puzzling Problems in Computer Engineering.
HandoutMay 2007Binary Search A Lecture in CE Freshman Seminar Series: Ten Puzzling Problems in Computer Engineering.
Chapter 3: The Efficiency of Algorithms Invitation to Computer Science, C++ Version, Third Edition Additions by Shannon Steinfadt SP’05.
Nov. 2004Math and ElectionsSlide 1 Math and Elections A Lesson in the “Math + Fun!” Series.
Chapter 3: The Efficiency of Algorithms Invitation to Computer Science, C++ Version, Fourth Edition.
Apr. 2007Easy, Hard, Impossible!Slide 1 Easy, Hard, Impossible! A Lecture in CE Freshman Seminar Series: Ten Puzzling Problems in Computer Engineering.
Chapter 3: The Efficiency of Algorithms
May 2007Binary SearchSlide 1 Binary Search A Lecture in CE Freshman Seminar Series: Ten Puzzling Problems in Computer Engineering.
HandoutMay 2007Sorting Networks A Lecture in CE Freshman Seminar Series: Ten Puzzling Problems in Computer Engineering.
May 2012Malfunction DiagnosisSlide 1 Malfunction Diagnosis A Lecture in CE Freshman Seminar Series: Ten Puzzling Problems in Computer Engineering.
May 2012Task SchedulingSlide 1 Task Scheduling A Lecture in CE Freshman Seminar Series: Ten Puzzling Problems in Computer Engineering.
Selection Sort, Insertion Sort, Bubble, & Shellsort
Apr. 2015Placement and RoutingSlide 1 Placement and Routing A Lecture in CE Freshman Seminar Series: Puzzling Problems in Computer Engineering.
May 2007String MatchingSlide 1 String Matching A Lecture in CE Freshman Seminar Series: Ten Puzzling Problems in Computer Engineering.
HandoutLecture 9Sorting Networks Rearranging Trains BADC Stub or lead BADC Sorted order BADC Stub or lead Stack or LIFO data structure in CE BADC Stub.
Lecture 2 TCP/IP Protocol Suite Reference: TCP/IP Protocol Suite, 4 th Edition (chapter 2) 1.
Chapter 6 Delivery and Forwarding of IP Packets
May 2015Sorting NetworksSlide 1 Sorting Networks A Lecture in CE Freshman Seminar Series: Ten Puzzling Problems in Computer Engineering.
Antenna Arrays and Automotive Applications
May 2007Sorting NetworksSlide 1 Sorting Networks A Lecture in CE Freshman Seminar Series: Ten Puzzling Problems in Computer Engineering.
CE2303 Railway Engineering
CMSC201 Computer Science I for Majors Lecture 19 – Recursion (Continued) Prof. Katherine Gibson Prof. Jeremy Dixon Based on slides from UPenn’s.
SCHOOL OF ENGINEERING Introduction to Electrical and Electronic Engineering Part 2 Pr. Nazim Mir-Nasiri and Pr. Alexander Ruderman.
Top 50 Data Structures Interview Questions
ECE 3301 General Electrical Engineering
7.1 What is a Sorting Network?
Forwarding and Routing IP Packets
Addressing: Router Design
Mathematical Illusions
What is an ANN ? The inventor of the first neuro computer, Dr. Robert defines a neural network as,A human brain like system consisting of a large number.
Design and Analysis of Algorithms
NET323 D: Network Protocols
Recommender Systems A Lecture in the Freshman Seminar Series:
Chapter 14 User Datagram Protocol (UDP)
3D Models from 2D Images A Lecture in the Freshman Seminar Series:
Satisfiability A Lecture in CE Freshman Seminar Series:
BINARY STORAGE AND REGISTERS
NET323 D: Network Protocols
Chapter 3: The Efficiency of Algorithms
Recommender Systems A Lecture in the Freshman Seminar Series:
Winter 2018 CISC101 12/2/2018 CISC101 Reminders
Easy, Hard, Impossible! A Lecture in CE Freshman Seminar Series:
Chapter 3: The Efficiency of Algorithms
Placement and Routing A Lecture in CE Freshman Seminar Series:
3D Models from 2D Images A Lecture in the Freshman Seminar Series:
Easy, Hard, Impossible! A Lecture in CE Freshman Seminar Series:
Malfunction Diagnosis
Last Class We Covered Recursion Stacks Parts of a recursive function:
Chapter 5 Transport Layer Introduction
Binary Search A Lecture in CE Freshman Seminar Series:
Computer Vision Lecture 19: Object Recognition III
Computer Networks: Switching and Queuing
Mathematical Illusions
Task Scheduling A Lecture in CE Freshman Seminar Series:
Switching Chapter 2 Slides Prepared By: -
WJEC GCSE Computer Science
Presentation transcript:

Sorting Networks A Lecture in CE Freshman Seminar Series: Ten Puzzling Problems in Computer Engineering Ron Zeno’s reference on the best sorting nets: http://www.angelfire.com/blog/ronz/Articles/999SortingNetworksReferen.html May 2016 Sorting Networks

About This Presentation This presentation belongs to the lecture series entitled “Ten Puzzling Problems in Computer Engineering,” devised for a ten-week, one-unit, freshman seminar course by Behrooz Parhami, Professor of Computer Engineering at University of California, Santa Barbara. The material can be used freely in teaching and other educational settings. Unauthorized uses, including any use for financial gain, are prohibited. © Behrooz Parhami Edition Released Revised First May 2007 May 2008 May 2009 May 2010 May 2011 May 2012 May 2015 May 2016 May 2016 Sorting Networks

Railroad Tracks and Switches May 2016 Sorting Networks

Coupling and Decoupling of Train Cars Train cars and engines can be coupled and decoupled quickly An engine can push a string of cars, or pull a desired subset by decoupling them from the rest May 2016 Sorting Networks

Railroad Yards Have Many Tracks and Switches If A < B, compare {A1, A2, B1} against {A3, B2, C1}; note that C coins are known to be normal. The three cases of left heavier, right heavier, and balance lead to the following conclusions: Left heavier: B1 heavier or A3 lighter. In the third step, compare B1 against a normal coin. Right heavier: B2 heavier or {A1, A2} lighter. In the third step, compare A1 and A2. Balance: A4 lighter or {B3, B4} heavier. In the third step, compare B3 and B4. May 2016 Sorting Networks

Rearranging Trains B A D C Track Train cars Engine B A D C Sorted order B A D C Stub or lead Stack or LIFO data structure in CE Sorting algorithm: Assemble train in stub, beginning with the last car Repeat: If the next car is X, decouple train after X, push X into stub B A Stub or lead D C Consider each problem with engine in front of the train (pulling it) and in the back (pushing it) B A D C Stub or lead B A D C Siding Queue or FIFO May 2016 Sorting Networks

Goleta Amtrak Station and Its Siding May 2016 Sorting Networks

Model Railroad Yard May 2016 Sorting Networks

Rearrangement with Change of Direction B A D C Turnaround loop B A D C B A D C Wye What types of sorting are possible with a turnaround loop? A wye? B A D C Configuration after the first few steps in sorting the train Complete the sorting process, assuming that it is okay for the engine to end up behind the train May 2016 Sorting Networks

Model Train Turntable May 2016 Sorting Networks

Delivering Train Cars in a Specific Order Cars in the train below have been sorted according to their delivery points. However, it is still nontrivial to deposit car A in stub 1, car B in stub 2, and car C in siding 3. Cars can be pulled or pushed by the engine. 1 B A D C 2 3 1 C 2 3 B A D 1 C 2 3 B A D Is there a better initial ordering of the cars for the deliveries in this puzzle? May 2016 Sorting Networks

Train Passing Puzzle The trains below must pass each other using a siding that can hold only one car or one engine. Show how this can be done. B A 2 1 B A 2 1 B 2 1 A B 2 1 A 2 1 A B 2 A B 1 May 2016 Sorting Networks

Fast Combining or Reordering of Train Cars Forming multiple trains from incoming cars B A D C Train reordering via a set of stubs Cars are pushed or pulled by an engine Alternatively, movement in one direction may be achieved via sloped rails Switches used to be adjusted manually, but nowadays, electronic control is used May 2016 Sorting Networks

Sorting Train Cars in Parallel Track 1 4 3 1 2 4 3 1 2 4 3 1 2 4 Track 2 2 Track 3 1 Unconditional exchange Track 4 3 Compare-exchange Target track 2 4 3 1 Track 1 Track 2 Track 3 Track 4 3 1 2 4 3 1 2 4 Is adding this compare-exchange element sufficient for producing a valid sorting network? The net in stick diagram schematic May 2016 Sorting Networks

Validating a Sorting Network b a d c Track 1 Track 2 Track 3 Track 4 min(a, b) max(a, b) min(a, b, c, d) ???? min(c, d) max(c, d) max(a, b, c, d) In the example above, it was fairly easy to show the validity of the sorting network. Generally, it is much more difficult Stick diagram schematic How would one establish the validity of this 16-input sorting network? More importantly, how does one come up with this design in the first place? May 2016 Sorting Networks

The Zero-One Principle A sorting net built of comparators is valid if it correctly sorts all 0-1 sequences 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 So, we can validate a sorting network using 2n rather than n! input patterns n = 12: 2n = 4096, n! = 479,001,600 (thousands vs. half a billion) May 2016 Sorting Networks

A 16-Input Sorting Network Use 4-input sorters, follow by (4, 4)-mergers, and end with an (8, 8)-merger 5 10 8 12 6 14 2 7 4 15 9 1 11 13 3 5 8 10 12 2 6 7 14 1 4 9 15 3 11 13 2 5 6 7 8 10 12 14 1 3 4 9 11 13 15 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Using the 0-1 principle, we can validate this network via 16 + 25 + 81 tests 4-sorter tests (4, 4)-merger tests (8, 8)-merger tests May 2016 Sorting Networks

Insertion Sort and Selection Sort 3 4 5 2 1 3 4 3 4 5 3 4 5 2 3 4 2 5 1 3 2 4 1 5 2 3 1 4 2 1 3 1 2 1 2 3 4 5 C(n) = n(n – 1)/2 D(n ) = 2n – 3 Cost  Delay = Q(n3) Fig. 7.8 Sorting network based on insertion sort or selection sort. May 2016 Sorting Networks

The Best Sorting Networks Which 10-input sorting network is better? Cost = 29 Cost = 31 Delay = 9 Delay = 7 Cost  Delay = 29  9 = 261 Cost  Delay = 31  7 = 217 Criterion 1: The number of sticks or compare-exchange blocks (cost) Criterion 2: The number of compare-exchanges in sequence (delay) Criterion 3: The product of cost and delay (cost-effectiveness) The most cost-effective n-input sorting network may be neither the fastest design, nor the lowest-cost design May 2016 Sorting Networks

Electronic Sorting Networks Electronic sorting networks are built of 2-sorters, building blocks that can sort two inputs a b min(a, b) max(a, b) Website that helps you synthesize sorting networks according to various algorithms: http://pages.ripco.net/~jgamble/nw.html (mark the bubble labeled “View the network using text characters if you can't view SVG”) Applications of sorting networks: Directing information packets to their destinations in a network router Connecting n processors to n memory modules in a parallel computer May 2016 Sorting Networks