Kumar-laxmi / Algorithms

A Repository for algorithms in C, C++, Python and Java
Apache License 2.0
326 stars 367 forks source link

Adding of pancake sort algorithms #1736

Closed Aarsh30 closed 1 year ago

Aarsh30 commented 1 year ago

Pancake Sort:

Pancake Sort is a fun and unique sorting algorithm that is based on the idea of flipping elements in the array to sort it. The goal is to sort the array using a series of pancake flips, where a flip consists of reversing the order of the first k elements in the array.

Algorithm Steps:

Start with the unsorted array. Find the index of the maximum element in the array. Perform a flip to move the maximum element to the beginning of the array. Perform another flip to move the maximum element to its correct sorted position (the end of the array). Repeat steps 2-4 for the remaining elements of the array, gradually reducing the portion of the array to be sorted. Continue these flips until the entire array is sorted.

Pancake Sort is known for its simplicity and the visual appeal of the flipping process. However, it's not considered an efficient sorting algorithm, especially for large datasets, as it has a time complexity of O(n^2).

@Kumar-laxmi assigned me so i can work and make pr.