Question
You have a row of 2n disks of two colors, n dark and n light like below. They alternate: dark, light, dark, light, and so
You have a row of 2n disks of two colors, n dark and n light like below. They alternate: dark, light, dark, light, and so on. You want to get all the dark disks to the right-hand end, and all the light disks to the left-hand end. The only moves you are allowed to make are those which interchange the positions of two neighboring disks.
(a) Design an algorithm for solving this puzzle. Present your algorithm in English or pseudo-code. In your algorithm, you have to minimize the number of interchanges.
(b) Determine the time efficiency of your algorithm.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started