Answered! 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.

●COCOCOO →CC00000.

(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.

Show transcribed image text

Expert Answer

 
Still stressed from student homework?
Get quality assistance from academic writers!