Question 1 (10%) You are given a n x n grid. Each grid intersection point can...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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! 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!
Expert Answer:
Answer rating: 100% (QA)
ANSWER SOLUTIONa PSEUDO CODE begin COLORGRIDAn1n1 for i1 to n1 for j1 to ... View the full answer
Related Book For
Posted Date:
Students also viewed these algorithms questions
-
Take a look at the reasons why cartels collapse presented in this chapter. For each of the following pairs, choose the case where the cartel is more likely to stick together. a. An industry where its...
-
Take a look at the Tesla electric car (www.teslamotors.com/). How is this company striving to build excitement and demand for its all-electric sports car?
-
Take a look at the US Census website, specifically https://www.census.gov/ and the chart labeled Quick Facts. Once you find your state, explore the information available. Choose one of these data...
-
General Ledger Accounts Account: Cash Date Description Opening Balance Account: Date Petty Cash Description Opening Balance Account: Date Accounts Receivable Description Opening Balance Account: Date...
-
The accounting records of Belmont Publishing Company include the following unadjusted balances at May 31: Accounts Receivable, $1,300; Supplies, $900; Salary Payable, $0; Unearned Service Revenue,...
-
To determine the effectiveness of an oil additive, a testing firm purchased two cars of the same make, year, and model, and drove each a distance of 30,000 miles using the same kind of gasoline, the...
-
On June 28, 1997, in Las Vegas, heavyweight boxers Mike Tyson and Evander Holyfield met for what proved to be a night to remember. During the third round of the fight, a desperate Tyson illegally bit...
-
A major source of revenue in Texas is a state sales tax on certain types of goods and services. Data are compiled and the state comptroller uses them to project future revenues for the state budget....
-
Imagine that you lend $5,000 to a friend at 7%, and say, "Pay me back when you get a job." Five years later, your friend gets a job and pays you back. Your friend assumed that you meant simple...
-
Amazon.com, Inc., headquartered in Seattle, WA, started its electronic commerce business in 1995 and expanded rapidly. The following transactions occurred during a recent year (dollars in millions):...
-
Suppose the United States and Mexico both produce hamburgers and tacos. The combinations of the two goods that each country can produce in one day are presented in the table below. Suppose the United...
-
What does MedPAC stand for, and what is its purpose?
-
What are the major differences between investor-owned and not-for-profit corporations?
-
What is a probability distribution?
-
From the following information ascertain the opening balance of sundry debtors and closing balance of sundry creditors. The rate of gross profit is 25% on selling price and out of the total sales Rs....
-
Draw block diagram showing the main components of a computer.
-
(a) [5 Points] Give examples of predicates P and Q and a domain of discourse so that the two statements Vx(P(x) Q(x)) and (VxP(x)) (VxQ(x)) are not equivalent. (b) [5 Points] Give an example where...
-
KD Insurance Company specializes in term life insurance contracts. Cash collection experience shows that 20 percent of billed premiums are collected in the month before they are due, 60 percent are...
-
1. Take the role of the marketing research projects director and draft all of the interviewer controls you believe are necessary to effect data collection comparable in quality to that gathered by a...
-
What is measurement? In your answer, differentiate an object from its properties, both objective and subjective.
-
A marketing manager of Collections, Etc, a Web-based catalog sales company, uses a segmentation scheme based on the incomes of target customers. The segmentation system has four segments: (1) low...
-
A diffraction grating is a closely spaced array of apertures or obstacles forming a series of closely spaced slits. The simplest type in which an incoming wave front meets alternating opaque and...
-
Find the position of the first minimum for a single slit of width 0.04 \(\mathrm{mm}\) on a screen of \(2 \mathrm{~m}\) distance, when light from a He-Ne laser \(\lambda=\) 6328 is shone on the slit.
-
A GaAs p-n junction has a \(100 \mu \mathrm{m} \times 100 \mathrm{~m}\) cross section and a width of the depletion layer \(W=440 \mathrm{~nm}\). Consider the junction in thermal equilibrium without...
Study smarter with the SolutionInn App