Answer the question
In order to leave comments, you need to log in
Which algorithm is more efficient in finding the minimum?
There are two algorithms for finding the minimum value in an unordered list.
#!/usr/bin/env python3
def find_smallest_int(arr):
min = arr[0]
for i in arr:
if i < min:
min = i
return min
#!/usr/bin/env python3
def findSmallestInt(arr):
arr.sort()
return arr[0]
Answer the question
In order to leave comments, you need to log in
first O(N)
second N*log(n) * C
for searching for one minimum, the first one is good
, and for multiple searches, the second one is good, paired with a banal binary search
The first one is correct.
With the second - you need to know what kind of sorting python uses and watch its complexity.
The task is to evaluate the complexity of algorithms or really find out "which algorithm is more efficient in finding a minimum"?
Because in the given examples it is an attempt to compare "warm with soft".
The first is REALLY looking for a minimum.
The second one REALLY sorts the array, and getting the minimum is a by-product.
Do you catch the difference?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question