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

#### Similar Solved Questions

##### 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...
##### 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...
##### How do you add 2sqrt3 + 2sqrt3?
How do you add 2sqrt3 + 2sqrt3?...
##### 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...
##### How do you evaluate 4- 3x = 7+ 4x?
How do you evaluate 4- 3x = 7+ 4x?...
##### 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?...
##### 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 ...
##### 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...
##### How do you factor 12x^2-39x+9?
How do you factor 12x^2-39x+9?...
##### 3x-2y=7 5x+4y=8
3x-2y=7 5x+4y=8...
##### 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...