Question

Describe an algorithm for finding the maximum (Large) value infinite sequence of integer 1.1 /10 points: Write a single sente
0 0
Add a comment Improve this question Transcribed image text
Answer #1

1. Finding the greatest number from the given n number of elements in an array.

2. For this, we will be having an array and we need to traverse through the whole array and thus find the maximum value out of the whole array.

3. Key assumption is that the numbers could be of any value applicable for integers and the array size would not be so big that it is not possible to calculate in a reasonable time.

4. For this, we need to traverse through the whole array linearly and thus keep track of the element which is maximum and thus at the last we will be having the element of maximum value. This would take O(n) time complexity to find.

5. The solution for the above problem is to linearly traverse the array and keep track of the current maximum value and while traversing if any element of greater value is found, we need to replace it will the current maximum value, Thus in this way we are keeping track of all the values without missing any value thus it is the correct solution.

max_element(a)
cur_max = 0
for I in a:
if I>cur_max:
cur_max = I
return cur_max

Thanks

Add a comment
Know the answer?
Add Answer to:
Describe an algorithm for finding the maximum (Large) value infinite sequence of integer 1.1 /10 points:...
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
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