3.1 Algorithms (Discrete Mathematics)

  • Thread starter modzz
  • Start date
  • #1
8
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.
 

Answers and Replies

  • #2
8
0
This does not answer my question though..
 
  • #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:

Related Threads on 3.1 Algorithms (Discrete Mathematics)

  • Last Post
Replies
1
Views
2K
V
Replies
1
Views
3K
  • Last Post
Replies
2
Views
2K
  • Last Post
Replies
0
Views
2K
  • Last Post
Replies
3
Views
4K
  • Last Post
Replies
6
Views
4K
  • Last Post
Replies
4
Views
764
  • Last Post
Replies
0
Views
1K
Replies
11
Views
8K
  • Last Post
Replies
3
Views
1K
Top