3.1 Algorithms (Discrete Mathematics)

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 5K views
modzz
Messages
8
Reaction score
0
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.
 
on Phys.org
This does not answer my question though..
 
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: