On the gameshow The Price is Right, contestants guess the price of an item, and the winner is the…

On the gameshow The Price is Right, contestants guess the price of an item, and the winner is the… | savvyessaywriters.org

On the gameshow The Price is Right, contestants gu

please do problem 4

On the gameshow The Price is Right, contestants guess the price of an item, and the winner is the person who guesses closest to the actual price without going over the actual price. For example, if the price of a refrigerator is $1529 and the contestants guess $1000, $1530, $1200, and $1600, then the person who guessed $1200 will win the refrigerator. If all guesses are too high, nobody wins. The following algorithm takes as input a list of guesses and an actual price, and determines the guess that is closest to the actual price without going over. All inputs are positive values. The algorithm returns 0 if all guesses are too high and there is no winner. procedure ClosestWithoutGoingOver(a_1, a_2, .. ., a_n: list of guesses, p: price, all positive) best:= 0 for i:= 1 to n if (a_i <= p AND a_i > best) best:= a_i return best Use a loop invariant to prove that the ClosestWithoutGoingOver algorithm given above is correct, i.e., that it returns the guess in the list that is closest to the price p without going over, and returns 0 if all guesses in the list are too high. Be sure to include all the parts of the proof: State the loop invariant precisely. Prove the loop invariant by induction on the number of loop iterations. Use the loop invariant to prove that the algorithm is correct as defined above. Design an algorithm that finds the index of the last even integer in a given list of integers or returns 0 if the list does not have any even integer: (Start your pseudocode like this:) procedure LastEven(a_1, a_2, .. ., a_n: list of integers) State the loop invariant precisely. Prove the loop invariant by induction on the number of loop iterations. Use the loop invariant to prove that the algorithm is correct as defined above.

 

Do you need a similar assignment done for you from scratch? We have qualified writers to help you. We assure you an A+ quality paper that is free from plagiarism. Order now for an Amazing Discount!
Use Discount Code “Newclient” for a 15% Discount!

NB: We do not resell papers. Upon ordering, we do an original paper exclusively for you.


The post On the gameshow The Price is Right, contestants guess the price of an item, and the winner is the… appeared first on Affordable Nursing Writers.