Write Algorithm to Find the Index of Largest Element in Sequence

  • Thread starter Thread starter Bucs44
  • Start date Start date
  • Tags Tags
    Algorithm Writing
Bucs44
Messages
57
Reaction score
0
I am having the hardest time getting this algorithm written:

Write an algorithm that returns the index of the first occurrence of the largest element in the sequence s1,..., sn. If the sequence is 6.2, 8.9, 4.2, 8.9, the algorithm returns the value 2.

Input: s, n

Output: ??

I'm stumped on this at the moment - Any help would be greatly appreciated.
 
Physics news on Phys.org
The output is m, where m is the index of the first occurence of the largest element.

But that isn't your problem, really, is it? Surely it is writing the algorithm (which is quite easy: how do you find the largest element in a list in a really naive way?) that is the issue, right?
 
There are two things I don't understand about this problem. First, when finding the nth root of a number, there should in theory be n solutions. However, the formula produces n+1 roots. Here is how. The first root is simply ##\left(r\right)^{\left(\frac{1}{n}\right)}##. Then you multiply this first root by n additional expressions given by the formula, as you go through k=0,1,...n-1. So you end up with n+1 roots, which cannot be correct. Let me illustrate what I mean. For this...

Similar threads

Replies
29
Views
3K
Replies
12
Views
3K
Replies
2
Views
1K
Replies
6
Views
7K
Replies
1
Views
2K
Replies
3
Views
4K
Back
Top