Question: Question 1 (10%) You are given a n x n grid. Each grid intersection point can be located using row and column indices. Take

Question 1 (10%) You are given a n x n grid. Each grid intersection point can be located using row and column indices. Take a look at the color pattern for n = 5. 1 2 3 4 5 1 Red Red Red Red Blue Blue Blue Blue Red Red Red Blue Blue Blue Blue Red Red Red Red Blue Blue Blue Blue W Red Red Red Red Blue Blue Blue 5 Blue Your are provided with the following function to color a triangle specified by ver- tices. paint (color, (i, j), (k, 1), (m, n)) will paint the triangle made out of (i, j), (k, 1) and (m, n) vertices with the color, color. Example: paint (red, (2, 2) (3, 2) (3, 3)) was used to color the above tri- angle in 5 x 5 grid. (a) Write an algorithm, COLORGRID(A), to paint n x n grid according to above color pattern. (5 points) (b) Analyze the running time of the algorithm and justify your answer. (5 points) Note: Do not write Java code. Pseudo code only!
Step by Step Solution
3.43 Rating (162 Votes )
There are 3 Steps involved in it
To solve this problem we need to understand the pattern of coloring triangles in the grid 1 Pattern ... View full answer
Get step-by-step solutions from verified subject matter experts
