+ 1
here i go again 🐸
if I'm looking for the maximum value in an array, then with what value do I need to compare each element? With zero or the first element in the index? The array contains only non-negative integer values.
6 Antworten
+ 6
One simple algorithm to find max value in an array:
- store first element of the array in a variable (max)
- loop through the array from second value to last
- if the element is greater than max, then assign this value to max
- you end up with the maximum when the loop is finished.
+ 2
look here for some sorting algorithms
https://www.sololearn.com/learn/774/?ref=app
https://www.sololearn.com/learn/652/?ref=app
+ 2
thanks to all of you, I know about the existence of the max () function, but I had a slightly different kind of task. I needed to find not just the maximum element.
+ 1
Array first element...,
(if lenear approache, so also it depends on your comparison methods..)
In python predefined function max() is there to find max as max(list); but for best practical purpose is to, define your own function.....
+ 1
you can convert the list into a numpy format and use the function maximum, that will return 2 parameters, the value and the position, i dont remember right now which is the order but 5 min in google will tell you 😉