Alert icon
We're changing our privacy policy. This stuff matters.  Learn more  Dismiss

Pancake sort algorithm, visualization with VTK

Loading...

Sign in or sign up now!
Alert icon
Upgrade to the latest Flash Player for improved playback performance. Upgrade now or more info.
6,333
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on Nov 13, 2009

Pancake sorting ( http://en.wikipedia.org/wiki/Pancake_sort ) is a variation of the sorting problem in which the only allowed operation is to reverse the elements of some prefix of the sequence. Unlike a traditional sorting algorithm, which attempts to sort with the least comparisons possible, the goal is to sort the sequence in as few reversals as possible. This operation can be visualized by thinking of a stack of pancakes in which one is allowed to take the top k pancakes and flip them.

Here we perform the visualization of a simple pancake sorting algorithm with VTK. The algorithm starts by flipping the top pancakes from the largest one to the top, so that the largest pancake goes to the top. Then, sorting the whole pancake stack we bring the largest pancake to the bottom. The subsequent move brings the second largest to the second position, and so on, recursively.

The VTK Python script is available here: http://www.cimec.org.ar/twiki/bin/view/Cimec/SomeVTKExamples

Category:

Science & Technology

Tags:

License:

Standard YouTube License

  • likes, 2 dislikes

Link to this comment:

Share to:

Uploader Comments (mariostorti)

  • Good illustration of the technique, but moves 9 and 10 were unnecessary, and at move 14, the stack is sorted. I guess your algorithm here simply repeats a sequence 2n times (for n pancakes) without checking for completion or redundancy. Tsk tsk!

  • Yes, you are right. In fact I programmed this with the simplest algorithm I found, as an example of programming with VTK-Python, rather than looking for the better algorithm.

see all

All Comments (3)

Sign In or Sign Up now to post a comment!
  • epic background music!! :D

Loading...
Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more