Shaker sort is really just like bubble sort, with one important improvement: the passes alternate between left-to-right and right-to-left:
In the unoptimized case, this doesn't help at all:
But with the same optimization as bubble sort (retiring multiple elements at once), the improvement becomes obvious:
The shaker improvement helps because it gets smaller elements out of the way more quickly. They tend to "gum up" bubble sort, preventing it from retiring many elements at once. But with shaker sorter, they get put in their proper locations more quickly.Shaker sort is also quite good with semisorted data, making it an adaptive sort.
Shaker sort is stable (like bubble sort):
Shaker sort is interesting because it illustrates that a tiny change can have big ramifications. But ultimately, the improvement just isn't enough. Shaker sort still is not used that often in the real world.
On to selection sort...