1. PF Contest - Win "Conquering the Physics GRE" book! Click Here to Enter
    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!

3.1 Algorithms (Discrete Mathematics)

  1. Oct 26, 2008 #1
    Describe an algorithm that takes as input a list of n distinct integers and finds the location of the largest even integer in the list or returns 0 if there are no even integers in the list.

    Please Help me on how to solve this type of question I am clueless.
  2. jcsd
  3. Oct 26, 2008 #2
    This does not answer my question though..
  4. Oct 26, 2008 #3
    O(n) time algorithm seems possible.

    You have n integers stored in an array, each having an index.
    When going through each index,

    1. if it is an even number, store it with an index. Otherwise go through next index.
    2. Compare it with the stored value if it is an even integer, and update the stored value if it is an even integer and it is bigger than the stored value.
    3. .........

    Remaining steps would be trivial.
    Last edited: Oct 26, 2008
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook