Question

Write pseudocode for an iterative algorithm which finds the maximum value of a list of integers....

Write pseudocode for an iterative algorithm which finds the maximum value of a list of integers. Use a loop invariant to prove your algorithm is correct. (Presumably you have already witten a program like this over the course of your studies! The interesting part here is the proof

0 0
Add a comment Improve this question Transcribed image text
Answer #1

-> Finds the maximum value of a list of interes Algorithm max(A) : Input: an array A storing nihtegles, . Where na l. Output:- Now, lets do the proofi Loop Invariant: At the start of the iteration with Lindex i of the loop, the variable man should coThere are two cases! (i) A[i] = max. From the loop invariant we get that act ] is deurger then the maximum of the hermbes in

Add a comment
Know the answer?
Add Answer to:
Write pseudocode for an iterative algorithm which finds the maximum value of a list of integers....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Describe a non-recursive algorithm that takes a list of distinct integers a_1, a_2, ...., a_n and...

    Describe a non-recursive algorithm that takes a list of distinct integers a_1, a_2, ...., a_n and finds the sum of the primes in the list. Write your answer in pseudo-code or any well-known procedural language like Python, Java, C++, ..... You do not need to write a function to determine whether a number is prime. Assume it is part of your language. E.g. For the list 2, 3, 4, 5, 6, 7, your program should return 17 (because 2 +...

  • a. Use pseudocode to specify a brute-force algorithm that takes as input a list of n...

    a. Use pseudocode to specify a brute-force algorithm that takes as input a list of n positive integers and determines whether there are two distinct elements of the list that have as their sum a third element of the list. That is, whether there exists i, j.k such that iヂj, i关k,j关k and ai + aj = ak. The algorithm should loop through all triples of elements of the list checking whether the sum of the first two is the third...

  • 8. Consider the following algorithm, which finds the sum of all of the integers in a...

    8. Consider the following algorithm, which finds the sum of all of the integers in a list procedure sum(n: positive integer, a1, a2,..., an : integers) for i: 1 to n return S (a) Suppose the value for n is 4 and the elements of the list are 3, 5,-2,4. List assigned to s as the procedure is executed. (You can list the the values that are values assigned to all variables if you wish) b) When a list of...

  • Write a program in MIPS assembly language that implements the DESCENDING bubble sort algorithm to sort a variable-sized array of signed 32-bit integers

    Write a program in MIPS assembly language that implements the DESCENDING bubble sort algorithm to sort a variable-sized array of signed 32-bit integers (words)that are read from the console. Be reminded that in a descending sort, the integers are sorted from the largest to the smallest. A “special value” 99999 will beused to signify the end of the input sequence. This value is not to be considered part of the input data set. However, any value greater than 99999 that...

  • Write a program that first gets a list of integers from input. The input begins with...

    Write a program that first gets a list of integers from input. The input begins with an integer indicating the number of integers that follow. Then, get the last value from the input, and output all integers less than or equal to that value. Ex: If the input is: 5 50 60 140 200 75 100 the output is: 50 60 75 The 5 indicates that there are five integers in the list, namely 50, 60, 140, 200, and 75....

  • Programming With the List of Elevations, Latitudes, & Longitudes Pseudocode Using CodeHS Sandbox, write a program...

    Programming With the List of Elevations, Latitudes, & Longitudes Pseudocode Using CodeHS Sandbox, write a program using the following guidelines: Program should have comments at the top with: program name, student name, date, and description of what the program does. Write a program that uses three separate functions: elevation_range, ave_position, and max_change. elevation_range will accept the elevation list as a parameter and find the range of elevation by finding the max elevation and min elevation and returning the difference (range...

  • 1.Write a function called high_point that takes a list of integers and returns True if there...

    1.Write a function called high_point that takes a list of integers and returns True if there exists a value in the list that is bigger than the values immediately before and after it in the list. Your function must return False if no such value exists. The values in the beginning and the end of the list cannot be high points. (20 points) Test Cases: print(high_point([2,5,8,9,7,9])) True print(high_point([2,5,6,6,3])) False print(high_point([2,5,8,21,22])) False 2. Write a while loop to repeatedly ask for...

  • C++ Problem 1 Write a function to calculate the greatest common divisor (GCD) of two integers...

    C++ Problem 1 Write a function to calculate the greatest common divisor (GCD) of two integers using Euclid’s algorithm (also known as the Euclidean algorithm). Write a main () function that requests two integers from the user, calls your function to compute the GCD, and outputs the return value of the function (all user input and output should be done in main ()). In particular, you will find this pseudocode for calculating the GCD, which should be useful to you:...

  • Using Python please Problem 3 (15 pts): Using the Secant Method, for A>0, (10 pts) Write a program which finds A/m for any positive value m. Note, you need to choose a function f(r) for the Secant...

    Using Python please Problem 3 (15 pts): Using the Secant Method, for A>0, (10 pts) Write a program which finds A/m for any positive value m. Note, you need to choose a function f(r) for the Secant Method whose root is A1 'm. (5 pts) How does your choice of m effect how many iterations your program takes to converge for a given tolerance choice? Plots will help me to understand your thinking here In [11]: #present your program for...

  • Requirement Write pseudocode and translate it to ONE C-program for each the following problems. In your...

    Requirement Write pseudocode and translate it to ONE C-program for each the following problems. In your pseudocode and C-program, use only what you have learned in this class so far. (Menu) Design a menu for question 2 and 3. So far, you use one program to solve all lab questions. But some of you may feel awkward when you want to demo/test only one lab question. To overcome that, your program should show a menu so that the users of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT