Computer Science, asked by pavan2312003, 5 months ago

algorithm to Smallest odd number in a set of N numbers

Answers

Answered by cuteprincess200012
1

Answer:

Use what is called a "watermark" algorithm. First apply a filter to isolate a list of odd numbers. Then create a variable representing the lowest number of the list and set it equal to float('inf').

Loop through the list and check each element; if its lower than the current min, set the current min equal to that element. At the end, whatever the value of the current min variable is will be the minimum of your list.

example code:

lst = [] ##input your list here

m = float('Inf')

odds = list(filter(lambda n: n%2, lst))

for ele in odds:

if ele < m: m = ele

print("The smallest odd is: ", m)

Similar questions