Question: 8 . ( 1 0 % ) Design an algorithm to solve a ball - picking problem. Problem statement: there are a number of

8.(10\%) Design an algorithm to solve a "ball-picking" problem.
Problem statement: there are a number of balls (n) placing in a circle, with all white except one red. Starting from any one of the balls, a robot travels along the circle in a clockwise direction, and pick a ball in every three balls (k=3 which means for every three balls, skip the first two balls, and picks the third one). The procedure is repeated with the remaining balls, starting with the next ball, the robot travels on the circle repeatedly, and pick balls in the same way until only one ball remains. In order to keep the red-ball remained at final, which ball has to be the first ball for robot to start with? Example:
Design your algorithm by giving an iteration/recurrence relation for the solution. Explain the time complexity and space complexity. Note that both time complexity and space complexity of your algorithm should not be more than O(n).
Show the starting ball of the right figure ( n=11, k=3) using your dynamic programming algorithm in order to have the red-ball #4 as the last ball to be remained.
8 . ( 1 0 \ % ) Design an algorithm to solve a

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!