Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi how to do this in python Exercise 1 -Pancake Sorting Pancake Sort is a colloquial term for the mathematical problem of sorting a disordered

image text in transcribed

Hi how to do this in python

Exercise 1 -Pancake Sorting Pancake Sort is a colloquial term for the mathematical problem of sorting a disordered stack of pancakes in order of size. A spatula can be inserted at any point i in the stack and used to flip all pancakes above it. Given an unsorted array, design and implement the pancake algorithm to sort it using only the "flip" operation, whose effect is to reverse the elements of the array between elements 0 and i (with i being the position where you imagine having inserted the spatula for flipping). Whereas a traditional sorting algorithm attempts to sort with the fewest comparisons possible, the goal here is to sort the sequence in as few "flips" as possible. Your algorithm should return the indices at which flips were performed. Example: Unsorted Input: [3,2,4,1] Sorted Output: [1,2,3,4] Algorithm Output: [1,2,3] indices where flips where performed (3 flips total). We have performed 3 flips (bold indicates it has been flipped): Start: [3,2,4,1] 1st flip (k=1):[2,3,4,1] 2nd flip (k=2):[4,3,2,1] 3rd flip (k=3):[1,2,3,4] Hint Intuitively, this problem can be solved by: - Finding the largest out-of-order value - Flip that largest unsorted value to the bottom (you may need to flip it to the top first) - Repeat until the pancake stack is ordered

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Database Systems Design Implementation And Project Management

Authors: Albert K.W. Yeung, G. Brent Hall

1st Edition

1402053932, 978-1402053931

More Books

Students also viewed these Databases questions

Question

Create a workflow analysis.

Answered: 1 week ago