Question

1). Describe an algorithm that takes a list of n integers a1,a2,...,an and find the average...

1). Describe an algorithm that takes a list of n integers a1,a2,...,an and find the average of the largest and smallest integers in the list.

Homework Answers

Answer #1

// Algorithm to find the largest and the smallest among the list of n integers a1....an and find the average of both

Procedure LargeSmallAvg(a1,...,an:Integers)

largest:=a1 // assume a1 is largest

smallest:=a1 // assume a1 is smallest

for i:= 2 to n // loop through remaining elements

if(ai > largest) // if ai is bigger than largest store ai in largest

largest:=ai

else if (ai < smallest) // if ai is smaller than smallest

// store ai in smallest

smallest:=ai

endif

endif

endfor

Avg:=(largest+smallest)/2 // take the average of smallest and //largest elements in the list

Display Avg // display the average

Know the answer?
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
Similar Questions
Describe an algorithm that takes as input a list of n integers and finds the location...
Describe an algorithm that takes as input a list of n integers and finds the location of the first even integer or returns -1 if there is no even integer in the list. Here is the operation's header: procedure locationOfFirstEven(a1, a2, a3, ..., an : integers)
Devise an algorithm that takes a list of n > 1 integers and finds the largest...
Devise an algorithm that takes a list of n > 1 integers and finds the largest and smallest values in the list.
1.13. Let a1, a2, . . . , ak be integers with gcd(a1, a2, . ....
1.13. Let a1, a2, . . . , ak be integers with gcd(a1, a2, . . . , ak) = 1, i.e., the largest positive integer dividing all of a1, . . . , ak is 1. Prove that the equation a1u1 + a2u2 + · · · + akuk = 1 has a solution in integers u1, u2, . . . , uk. (Hint. Repeatedly apply the extended Euclidean algorithm, Theorem 1.11. You may find it easier to prove...
design an algorithm in a c++ function that takes as input a list of n integers...
design an algorithm in a c++ function that takes as input a list of n integers and find the location of the last even integer in the list or returns 0 if there are no even integers in the list
Pseudocode an algorithm that takes as input a list of n integers and finds the number...
Pseudocode an algorithm that takes as input a list of n integers and finds the number of even integers in the list.
Find positive numbers n and a1 ,a2,...,an such that a1 + . . . an =...
Find positive numbers n and a1 ,a2,...,an such that a1 + . . . an = 1000 and the product a1 a2 . . . is as large as possible. Also prove why?
Let a1, a2, ..., an be distinct n (≥ 2) integers. Consider the polynomial f(x) =...
Let a1, a2, ..., an be distinct n (≥ 2) integers. Consider the polynomial f(x) = (x−a1)(x−a2)···(x−an)−1 in Q[x] (1) Prove that if then f(x) = g(x)h(x) for some g(x), h(x) ∈ Z[x], g(ai) + h(ai) = 0 for all i = 1, 2, ..., n (2) Prove that f(x) is irreducible over Q
(8 marks) Let S = {(a1, a2, . . . , an)| n ≥ 1, ai...
Let S = {(a1, a2, . . . , an)| n ≥ 1, ai ∈ Z ≥0 for i = 1, 2, . . . , n, an 6= 0}. So S is the set of all finite ordered n-tuples of nonnegative integers where the last coordinate is not 0. Find a bijection from S to Z +.
Use Big-O Notation to characterize the computational cost of algorithm A1 and A2. The complexity of...
Use Big-O Notation to characterize the computational cost of algorithm A1 and A2. The complexity of A1 is 10000 * n, with n being the number elements processed in A1. The complexity of A2 is 100 * n, with n elements in A2. State in Big-O notation the cost of f1, with f1(x) = log2(2x) – 14x + 3 sqrt(x) + 12x^2 - 150 this is also a theoretical question just answer no code.
1) Suppose a1, a2, a3, ... is a sequence of integers such that a1 =1/16 and...
1) Suppose a1, a2, a3, ... is a sequence of integers such that a1 =1/16 and an = 4an−1. Guess a formula for an and prove that your guess is correct. 2) Show that given 5 integer numbers, you can always find two of the numbers whose difference will be a multiple of 4. 3) Four cats and five mice form a row. In how many ways can they form the row if the mice are always together? Please help...