3.1 Algorithms (Discrete Mathematics)

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.
 
Physics news 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:
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...
Back
Top