Pancake Sort is a sorting algorithm which derives from the pancake problem. The algorithm just executes the flip operation recursively until the data structure is sorted. It's similar to Selection Sort, without using swaps to sort the structure, but just flips.
The data structure gets divided in two parts, a sorted one and one still to sort. For each flip, the maximum elements of the unsorted sublist gets put at the end of the data structure by flipping the unsorted part and the sorted sublist gets incremented by one. This procedure gets executed until the unsorted part is made up of just one element.
Average Complexity | O(n^{2}) |
---|---|
Best Case | O(n^{2}) |
Worst Case | O(n^{2}) |
Space Complexity | O(1) |