Sorting with Cranes - PowerPoint PPT Presentation

About This Presentation
Title:

Sorting with Cranes

Description:

Sorting with Cranes. Mike Atkinson. University of Otago. Joint work with Michael Albert ... Mental image: a stack of boxes being manipulated by a forklift or a crane. ... – PowerPoint PPT presentation

Number of Views:28
Avg rating:3.0/5.0
Slides: 35
Provided by: michael596
Category:
Tags: crane | cranes | sorting

less

Transcript and Presenter's Notes

Title: Sorting with Cranes


1
Sorting with Cranes
  • Mike Atkinson
  • University of Otago
  • Joint work with Michael Albert

2
Question
  • Why is a stack limited to pushing or popping one
    item at a time?
  • Algorithmically to implement last in-first out
    behaviour.
  • Implementationally no reason at all.
  • In fact, block pops may be more efficient than
    single element pops in a linked list
    implementation.

3
Enter the forkstack
  • Storage as for a stack
  • Push a sequence of arbitrary length (but first
    element winds up on top)
  • Pop a sequence of arbitrary length.
  • Mental image a stack of boxes being manipulated
    by a forklift or a crane.

4
Moving from input to output
Input
Forkstack
Output
5
Questions
  • Which rearrangements of an input sequence are
    possible?
  • Alternatively, which input sequences can be
    sorted?

6
Sorting 236415
Input
Output
Forkstack
7
Sorting 236415
Input
Output
Forkstack
8
Sorting 236415
Input
Output
Forkstack
9
Sorting 236415
Input
Output
Forkstack
10
Sorting 236415
Input
Output
Forkstack
11
Sorting 236415
Input
Output
Forkstack
12
Sorting 236415
Input
Output
Forkstack
13
Sorting 236415
Input
Output
Forkstack
14
Sorting 236415
Input
Output
Forkstack
15
Sorting 236415
Sorted means increasing from top to bottom
Input
Output
Forkstack
16
Which sequences are sortable?
  • Concrete approach seek an algorithm that sorts
    input sequences whenever this is possible.
  • Abstract approach seek a characterisation of
    obstructions to sortability (bad configurations)
  • Or in between

17
The dreaded 13
  • If, in the stack, an element sits directly on top
    of a larger, but not next larger, element, then
    we cannot recover.
  • First abstract characterisation
  • A sequence is unsortable if any schedule of
    moves that does not produce bad output,
    eventually produces the dreaded 13.
  • Not tremendously useful!

18
Or is it?
  • Use the idea of avoiding 13s at all costs as the
    primary component of an algorithm for sorting.
  • Only extra ingredient doing output when you can
    is never harmful.

19
Sorting 236415
  • The 23 at the top need never be split.
  • In fact, they should never be split.
  • We cant move it with the 6 because of the
    dreaded 13 (36 in this case)

20
Sorting 326415
  • The 32 at the stop still need to be moved before
    the 6.
  • But they should be moved one element at a time,
    to reduce the chances of a later dreaded 13.

21
Almost decreasing?
  • A sequence is almost decreasing if it is
    decreasing, except for some steps of 1.
  • Eg 14 12 8 9 5 2 3 4 1
  • To avoid the dreaded 13 the maximal initial
    almost decreasing subsequence of the input needs
    to be moved before the next element.
  • As a block if non-consecutive.
  • To make it increasing if consecutive.

22
The algorithm
  • repeat
  • As much output as possible
  • Move the a.d. head as above
  • until input is empty
  • if stack is empty
  • Hurray!
  • else
  • Waah!

Linear time test for forkstack sortability
23
Modifications
  • We may wish to consider the case where either the
    push, the pop, or both operations are limited in
    size (dishwasher and stower)
  • No real need to change the algorithm, it may just
    fail earlier when a move is required which
    overloads an operations capacity.

24
Being obstructive
  • Any unsortable sequence contains a minimal
    unsortable subsequence.
  • The algorithm implies that there are (to within
    renaming) a finite number of such
  • examine the stack just before a crash
  • determine what went wrong and why
  • In fact, they are 35142, together with 45 of
    length six, and 6 of length 7.

25
Counting
  • We wish to count the number of sortable
    permutations of each length.
  • This allows us to compare the powers of various
    forkstack models,
  • And to compare the sorting power of forkstacks
    with other data structures.

26
The forkstack in the kitchen
  • The awful truth
  • Sometimes the kitchen has no automatic dishwasher
  • Washing dishes has to be done by people!

27
Washing, drying, and stowing
Forkstack with one-element pushes, multi-element
pops
28
Washing, drying, and stowing
When dish t is washed the drying stack is empty
When dish t-1 is washed the drying stack contains
t only
2
1
The intermediate dish segments are sortable
segments on ranges of values
29
Washing, drying, and stowing
a0 lt a1 lt at
30
Washing, drying, and stowing
This recursive decomposition allows the counting
problem to be solved in this case. Let cn be the
number of sortable permutations if the push
operation is of single items and the pop
operation is unlimited. Define
Geometric series
Then
31
Employ weaker stowers?
  • If the stower can move just one dish at a time,
    thats sorting on an ordinary stack.
  • Powerful stowers discussed above.
  • In between? The two cases above correspond to the
    first term, and entire sum of the geometric
    series. The intermediate cases impose a limit on
    the size of t and are exactly the partial sums.
  • Should we pay for a powerful stower?

32
Employ weaker stowers?
  • The equations tell us that a stower who can lift
    up to k dishes allows about akn dish sequences of
    length n to be stowed in order
  • a14 a24.730 a34.919 a44.976
  • a54.993 a64.998 .. a? 5
  • Local improvements in the manipulation of data
    rapidly lose their effectiveness.

33
Other parameters
  • We know about the sorting power of a forkstack if
    pushes of s1 items and pops of any length t are
    allowed.
  • What about other values of s and t?
  • The only solved case is s2, t2. Here we can
    sort about 5.412n sequences of length n (so st2
    is more powerful than s1, t ? )
  • If s ?, t ? we can sort at most 9n sequences of
    length n

34
Open question
  • Solve the counting problem for the case s ?, t
    ?
Write a Comment
User Comments (0)
About PowerShow.com