+ 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.

11th Apr 2020, 6:10 AM
shiryaeva
shiryaeva - avatar
6 Réponses
+ 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.
11th Apr 2020, 6:48 AM
Tibor Santa
Tibor Santa - avatar
11th Apr 2020, 6:32 AM
John Robotane
John Robotane - avatar
+ 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.
11th Apr 2020, 10:31 AM
shiryaeva
shiryaeva - avatar
+ 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.....
11th Apr 2020, 6:50 AM
Jayakrishna 🇮🇳
+ 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 😉
11th Apr 2020, 10:23 AM
Vicente Gras Mas
Vicente Gras Mas - avatar