1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Algorithm writing

  1. Jan 21, 2007 #1
    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.
  2. jcsd
  3. Jan 21, 2007 #2

    matt grime

    User Avatar
    Science Advisor
    Homework Helper

    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?
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Discussions: Algorithm writing
  1. Euclid's Algorithm (Replies: 5)

  2. Euclidean algorithm (Replies: 3)

  3. Division Algorithm (Replies: 3)

  4. Reme's algorithm (Replies: 5)

  5. Division algorithm (Replies: 13)