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

Slides:



Advertisements
Similar presentations
Topic 16 Sorting Using ADTs to Implement Sorting Algorithms.
Advertisements

 Abstract Data Type Abstract Data Type  What is the difference? What is the difference?  Stacks Stacks  Stack operations Stack operations  Parsing.
Brute-Force Triangulation
CS 206 Introduction to Computer Science II 03 / 02 / 2009 Instructor: Michael Eckmann.
HST 952 Computing for Biomedical Scientists Lecture 9.
Stephen P. Carl - CS 2421 Recursive Sorting Algorithms Reading: Chapter 5.
CS 206 Introduction to Computer Science II 03 / 06 / 2009 Instructor: Michael Eckmann.
Recursion. Objectives At the conclusion of this lesson, students should be able to Explain what recursion is Design and write functions that use recursion.
Introduction to Bioinformatics Algorithms Greedy Algorithms And Genome Rearrangements.
CS 206 Introduction to Computer Science II 10 / 15 / 2008 Instructor: Michael Eckmann.
Dynamic Programming Optimization Problems Dynamic Programming Paradigm
Aho-Corasick String Matching An Efficient String Matching.
Part-B1 Stacks. Stacks2 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data structure An ADT specifies: Data stored Operations.
Recursion.
CS 206 Introduction to Computer Science II 03 / 16 / 2009 Instructor: Michael Eckmann.
1 Parallel Algorithms III Topics: graph and sort algorithms.
Sorting and Searching Algorithms Week 11 DSA. Recap etc. Arrays are lists of data 1-D, 2-D etc. Lists associated with searching and sorting Other structures.
Hashing General idea: Get a large array
Sorting Chapter 10. Chapter 10: Sorting2 Chapter Objectives To learn how to use the standard sorting methods in the Java API To learn how to implement.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Data Structures Stacks.
CS 206 Introduction to Computer Science II 10 / 08 / 2008 Instructor: Michael Eckmann.
Important Problem Types and Fundamental Data Structures
EXPANDING STACKS AND QUEUES CS16: Introduction to Data Structures & Algorithms 1 Tuesday, February 10, 2015.
Triangulating a monotone polygon
1 Time Analysis Analyzing an algorithm = estimating the resources it requires. Time How long will it take to execute? Impossible to find exact value Depends.
Week 5 - Monday.  What did we talk about last time?  Linked list implementations  Stacks  Queues.
Nonvisual Arrays and Recursion by Chris Brown under Prof. Susan Rodger Duke University June 2012.
Merge Sort. What Is Sorting? To arrange a collection of items in some specified order. Numerical order Lexicographical order Input: sequence of numbers.
Recursion Textbook chapter Recursive Function Call a recursive call is a function call in which the called function is the same as the one making.
Chapter 13 Recursion. Learning Objectives Recursive void Functions – Tracing recursive calls – Infinite recursion, overflows Recursive Functions that.
© 2004 Goodrich, Tamassia Stacks. © 2004 Goodrich, Tamassia Stacks2 Abstract Data Types (ADTs) An abstract data type (ADT) is an abstraction of a data.
Greedy Algorithms And Genome Rearrangements An Introduction to Bioinformatics Algorithms (Jones and Pevzner)
Elementary Sorting Algorithms Many of the slides are from Prof. Plaisted’s resources at University of North Carolina at Chapel Hill.
Genome Rearrangements [1] Ch Types of Rearrangements Reversal Translocation
Greedy Algorithms And Genome Rearrangements
CS 61B Data Structures and Programming Methodology July 28, 2008 David Sun.
CS 361 – Chapters 8-9 Sorting algorithms –Selection, insertion, bubble, “swap” –Merge, quick, stooge –Counting, bucket, radix How to select the n-th largest/smallest.
1 Section 2.1 Algorithms. 2 Algorithm A finite set of precise instructions for performing a computation or for solving a problem.
Chapter 8 Arrays Instructor: Kun-Mao Chao ( 台大資工 趙坤茂 )
Understanding General Software Development Lesson 3.
Introduction to Bioinformatics Algorithms Chapter 5 Greedy Algorithms and Genome Rearrangements By: Hasnaa Imad.
Sorting Fundamental Data Structures and Algorithms Aleks Nanevski February 17, 2004.
CS 206 Introduction to Computer Science II 10 / 10 / 2008 Instructor: Michael Eckmann.
1. Searching The basic characteristics of any searching algorithm is that searching should be efficient, it should have less number of computations involved.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 4: Introduction to C: Control Flow.
Stacks A stack is a linear data structure that can be accessed only at one of its ends for storing and retrieving data LIFO (Last In First Out) structure.
Onlinedeeneislam.blogspot.com1 Design and Analysis of Algorithms Slide # 1 Download From
Sorting: Parallel Compare Exchange Operation A parallel compare-exchange operation. Processes P i and P j send their elements to each other. Process P.
Recursion. Objectives At the conclusion of this lesson, students should be able to Explain what recursion is Design and write functions that use recursion.
CMPT 120 Topic: Searching – Part 2 and Intro to Time Complexity (Algorithm Analysis)
BINARY SEARCH CS16: Introduction to Data Structures & Algorithms Thursday February 12,
Understanding General Software Development Lesson 3.
chap10 Chapter 10 Recursion chap10 2 Recursive Function recursive function The recursive function is a kind of function that calls.
CPS120: Introduction to Computer Science Sorting.
Chapter 11 Sorting Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and Mount.
Chapter 13 Recursion Copyright © 2016 Pearson, Inc. All rights reserved.
Sort & Search Algorithms
Recursion Version 1.0.
Data Structures Recursion CIS265/506: Chapter 06 - Recursion.
Selection Selection 1 Quick-Sort Quick-Sort 10/30/16 13:52
Algorithm design and Analysis
Dynamic Programming.
Fundamentals of Programming
Advanced Algorithms Analysis and Design
Sorting "There's nothing in your head the sorting hat can't see. So try me on and I will tell you where you ought to be." -The Sorting Hat, Harry Potter.
Algorithms: the big picture
Quick-Sort 4/25/2019 8:10 AM Quick-Sort     2
Last Class We Covered Recursion Stacks Parts of a recursive function:
Chapter 13 Recursion Copyright © 2010 Pearson Addison-Wesley. All rights reserved.
Presentation transcript:

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

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.

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.

Moving from input to output InputForkstackOutput

Questions Which rearrangements of an input sequence are possible? Alternatively, which input sequences can be sorted?

Sorting InputOutputForkstack

Sorting InputOutputForkstack

Sorting InputOutputForkstack

Sorting InputOutputForkstack

Sorting InputOutputForkstack

Sorting InputOutputForkstack

Sorting InputOutputForkstack

Sorting InputOutputForkstack

Sorting InputOutputForkstack

Sorting InputOutput “Sorted” means “increasing from top to bottom” Forkstack

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 …

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! 1 3

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

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

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

Almost decreasing? A sequence is almost decreasing if it is decreasing, except for some steps of +1. Eg 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.

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

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 operation’s capacity.

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.

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.

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

Washing, drying, and stowing n - 2 n - 1 n Dirty dishesDrying stackOrderly cupboard washstow Forkstack with one-element pushes, multi-element pops

Washing, drying, and stowing 1 2 Other dishes When dish t is washed the drying stack is empty When dish t-1 is washed the drying stack contains t only The intermediate dish segments are sortable segments on ranges of values t t -1 Other dishes Maximal t

Washing, drying, and stowing 1 2 Sortable segment  t t t -1 Sortable segment  t-1 Maximal t Sortable segment  1 Sortable segment  0  0 <  1 < …  t

Washing, drying, and stowing f = 1 + xf + (f - 1)  x t f t t = 0 8 This recursive decomposition allows the counting problem to be solved in this case. Let c n be the number of sortable permutations if the push operation is of single items and the pop operation is unlimited. Define f = f(x) =  c n x n n = 0 8 Then Geometric series

Employ weaker stowers? If the stower can move just one dish at a time, that’s 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?

Employ weaker stowers? The equations tell us that a stower who can lift up to k dishes allows about  k n dish sequences of length n to be stowed in order  1 =4  2 =4.730  3 =4.919  4 =4.976  5 =4.993  6 =4.998 …..    =5 Local improvements in the manipulation of data rapidly lose their effectiveness.

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

Open question Solve the counting problem for the case s = , t = 