Sorting Networks A Lecture in CE Freshman Seminar Series: Handout

Download Report

Transcript Sorting Networks A Lecture in CE Freshman Seminar Series: Handout

Sorting Networks
A Lecture in CE Freshman Seminar Series:
Ten Puzzling Problems in Computer Engineering
May 2007
Sorting Networks
Handout
Rearranging Trains
Train cars
B
Engine
A
D
Track
C
Sorted order
D
C
B
A
Stub or lead
B
A
D
C
Stack or LIFO data structure in CE
B
A
D
C
Stub or lead
Stub or lead
C
A
B
D
Question: Is there an ordering that cannot be sorted using a stub?
Devising a sorting algorithm
C
A
B
D
Queue or FIFO
May 2007
Sorting Networks
Siding
Handout
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.
2
C
B
A
D
1
3
1
3
1
3
2
2
Is there a better initial ordering of the cars for the deliveries in this puzzle?
May 2007
Sorting Networks
Handout
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
May 2007
1
Sorting Networks
2
Handout