Question

Given this pseudocode:   input: sequence of numbers ak k, length of sequence answer := a1 for...

Given this pseudocode:

  input: sequence of numbers ak
k, length of sequence

answer := a1

for i = 2 to k
if (ai > answer), then answer = ai
End-for

What is the value of answer for the sequence {-1, 4, -7, 10, 2} with k = 5?

Please provide detailed answer! Thank you!

Homework Answers

Answer #1

Here a1 = -1, a2=4, a3=-7, a4=10, a5=2

answer=a1=-1

The loop will run from i=2 to 5.

@ i= 2 , a2>answer, so answer => 4

@ i= 3 , a3! >answer , so value of answer remains same ie 4.

@ i=4 , a4>answer is True, so answer = a4= 10

@ i=5 , a5>answer is False, so value of answer remains unchanged.

Thus the value of answer is 10.

The given sequence is finding maximum value of the given sequence.

If you have any questions comment down. Please don't simply downvote and leave. If you are satisfied with answer, please? upvote thanks

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
Given this algorithm written in pseudocode:   Algo(n) Input: A positive integer n Output: Answer, Algo(n) If...
Given this algorithm written in pseudocode:   Algo(n) Input: A positive integer n Output: Answer, Algo(n) If n = 1 Answer = 3 Else Answer = 3 × Algo(n-1) End if What is Algo(4)? Please provide a detailed answer! thank you!
10. Let P(k) be the following statement: ”Let a1, a2, . . . , ak be...
10. Let P(k) be the following statement: ”Let a1, a2, . . . , ak be integers and p be a prime. If p|(a1 · a2 · a3 · · · ak), then p|ai for some i with 1 ≤ i ≤ k.” Prove that P(k) holds for all positive integers k
. Consider the sequence defined recursively as a0 = 5, a1 = 16 and ak =...
. Consider the sequence defined recursively as a0 = 5, a1 = 16 and ak = 7ak−1 − 10ak−2 for all integers k ≥ 2. Prove that an = 3 · 2 n + 2 · 5 n for each integer n ≥ 0
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...
We are given a sequence of numbers: 1, 3, 5, 7, 9, . . . and...
We are given a sequence of numbers: 1, 3, 5, 7, 9, . . . and want to prove that the closed formula for the sequence is an = 2n – 1.          What would the next number in the sequence be? What is the recursive formula for the sequence? Is the closed formula true for a1? What about a2? What about a3? Critical Thinking How many values would we have to check before we could be sure that the...
Let A = (A1, A2, A3,.....Ai) be defined as a sequence containing positive and negative integer...
Let A = (A1, A2, A3,.....Ai) be defined as a sequence containing positive and negative integer numbers. A substring is defined as (An, An+1,.....Am) where 1 <= n < m <= i. Now, the weight of the substring is the sum of all its elements. Showing your algorithms and proper working: 1) Does there exist a substring with no weight or zero weight? 2) Please list the substring which contains the maximum weight found in the sequence.
The programmer intends for this pseudocode to display three random numbers in the range of 1...
The programmer intends for this pseudocode to display three random numbers in the range of 1 through 10. Locate the error and clearly explain the error. // This program displays three random numbers in the range of 1 through 10. Declare Integer count Declare Real value // Display three random numbers. For count = 1 To 5 Step 2 Set value = count Display random(10, 1) End For
Java please. Given a sequence of unsorted numbers, determine how badly out of order they are....
Java please. Given a sequence of unsorted numbers, determine how badly out of order they are. Write a program that, for any given sequence of unique natural numbers, will compute the 'distance' between that original ordering and the same set of numbers sorted in ascending order. The distance should be computed by calculating how far displaced each number is in the original ordering from its correct location in the sorted list and summing those results. For instance, given the list...
C++ only. Must use loops. Please do not use sequence of if statements. Given as input...
C++ only. Must use loops. Please do not use sequence of if statements. Given as input string and an int N, set result a string made of N repetitions of the last N characters of the string. You may assume that N is between 0 and the length of the string, inclusive.   • for input of "Hello", 3 → "llollollo" • for input of "Hello", 2 → "lolo" • for input of "Hello", 1 → "o"
A sequence is a list of numbers that are calculated based on a certain rule. For...
A sequence is a list of numbers that are calculated based on a certain rule. For instance, the progression described by the rule An = 2 ∗ n results in the numbers: 0 2 4 6 8 10 ··· 2 ∗ n. The sum of this sequence can be calculated as Sn = 0+2+4+6+8+10+···+2 ∗ n. Write a function that takes as input the number n and calculates the sum of the sequence up to the nth term (inclusive) for...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT