1 answer

6. Consider the following algorithm, where P is an array containing random numbers. The function swap(v1,v2)...

Question:

6. Consider the following algorithm, where P is an array containing random numbers. The function swap(v1,v2) will swap the va

6. Consider the following algorithm, where P is an array containing random numbers. The function swap(v1,v2) will swap the values stored in the variables v1 and v2. Note that % is the modulus operation, and will return the integer remainder r of a/b, i.e., r-a%b Require: Array P with n > 0 values 1: i-1, j-n-l 2: while i<=j do for a=i to j by i do 4: 5: 6: 7: if Pla>Pat 11 and Pla]%2--0 then swap(Plal, Pla+1l) end if 9 end for 10: -y-1 1 for a-j-1 toi by1 do 12: if Pla> Pla-11 and Pla]%2-0 then 13: 14: 15: 16: end for 17: -x+1 18: end while swap(Pla], Pla+1) x-a end if (a) (1 point) What are the input(s) to the algorithm? (b) (2 points) In one short sentence explain what the purpose of the algorithm is. Be as specific as possible by referring to program variables (c) (10 points) Provide a proof of correctness using a loop invariant. Be sure to clearly state the invariant. HINT: after each iteration of the outer loop, largest even element of the array is always placed at rightmost position. (d) (3 points) What is a best-case runtime scenario for this algorithm? Explain (e) (3 points) What is a worst-case runtime scenario for this algorithm? Explain.

Answers

The function swap v,v) Oİ Adot aw tle飆.tos, -to -el.e agorthm. Fn one dort Sentence expafn んlat tle Rwpaseal the The agerithres what is ost case aumti ne Scevaiofoa this a while bopOin) (fox loop--> O(n) foy loop both for (ooPs T s (2n) .l-e (n)

.

Similar Solved Questions

1 answer
Question 2 1 pts As in the figure, a uniform sphere of mass = 0.82 kg...
Question 2 1 pts As in the figure, a uniform sphere of mass = 0.82 kg and radius r = 5 cm is supported by a string (of negligible mass) attached to a wall (whose friction can also be ignored). The center of the sphere is a vertical distance L = 8.5 cm below the attachment point of the string. Find t...
1 answer
The switch has been in position A for a long time and is moved to position...
The switch has been in position A for a long time and is moved to position B at t = 0. Find iL(t) and vC(t) for t < 0 and t > 0. 20k1 B 1=0 4. The switch has been in position A for a long time and is moved to position B at t = 0. Find il(t) and vc(t) for t< 0 and t> 0. il(0) (6) o +| 10...
1 answer
How do you add #2sqrt3 + 2sqrt3#?
How do you add #2sqrt3 + 2sqrt3#?...
1 answer
A) D om medles, rubella (MMR) There is aware that the foo t outinely used during...
A) D om medles, rubella (MMR) There is aware that the foo t outinely used during the of Need to a patient 5 percent dextrose in water solution B) 0.9 percent odium chloride (normal saline) c) Stavile water D) Hapurin sodium A male patient needs to receive a unit of whole blood. What type of intraven...
1 answer
How do you evaluate #4- 3x = 7+ 4x#?
How do you evaluate #4- 3x = 7+ 4x#?...
1 answer
What is the square root of 7 + square root of 7^2 + square root of 7^3 + square root of 7^4 + square root of 7^5?
What is the square root of 7 + square root of 7^2 + square root of 7^3 + square root of 7^4 + square root of 7^5?...
1 answer
36. The Sun is primarily made of ___ hydrogen B) helium C) hydrogen and helium D)...
36. The Sun is primarily made of ___ hydrogen B) helium C) hydrogen and helium D) nitrogen 37. Blue is associated with_ wavelengths. A) long B) medium C) short D) red 38. Our Sun is . Aaverage in size B) larger than most stars C) smaller than most stars D) hotter than most stars 39. A_ is formed in ...
1 answer
The marginal revenue (in thousands of dollars) from the sale of x gadgets is given by...
The marginal revenue (in thousands of dollars) from the sale of x gadgets is given by the following function. win R'(x) = 4x(x2 + 28,000) a. Find the total revenue function if the revenue from 120 gadgets is $19,222. b. How many gadgets must be sold for a revenue of at least $35,000? a. The tota...
2 answers
How do you factor #12x^2-39x+9#?
How do you factor #12x^2-39x+9#?...
1 answer
3x-2y=7 5x+4y=8
3x-2y=7 5x+4y=8...
1 answer
Which do you think will have a larger impact on the density of a ceramic a...
Which do you think will have a larger impact on the density of a ceramic a Frenkel or Schottky defect? Why? Explain why thermoplastics can be softened by heating as opposed to thermosets. Show how two phase regions only need one variable to complete define the phase compositions as opposed to single...
1 answer
Please show all work The Chernobyl power station was capable of producing 4.00 x 103 Mw...
Please show all work The Chernobyl power station was capable of producing 4.00 x 103 Mw of electrical power, prior to the disaster at one of its four reactors in 1986. Assuming that each fission reaction produces about 200 Mev and that the power plant is about 25.4% efficient, determine that ass ofU...
1 answer
After constructing a relative frequency distribution summarizing IQ scores of college students, what should be the...
After constructing a relative frequency distribution summarizing IQ scores of college students, what should be the sum of the relative frequencies? Choose the correct answer below. A. If percentages are used, the sum should be 100% O B. If percentages are used, the sum should be 100% ° C. If per...
1 answer
Rate sensitive funding sources at a bank are termed core deposits. true or false
rate sensitive funding sources at a bank are termed core deposits. true or false...
1 answer
E14.21 LO14.1 14.2 Financial and non-financial measures Classify each of the following statements as true or...
E14.21 LO14.1 14.2 Financial and non-financial measures Classify each of the following statements as true or false. In each case give reasons for your answer. 1 Non-financial performance measures provide essential information in order to assist managers at the operational level to take actions to co...