Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find Maximum Integer in Array?

I have two arrays, one is very large (more than million entries) and other array is small (less than 1000 entries), what would be the best approach to find maximum number out of all entries in arrays ?

Thanks.

like image 270
Rachel Avatar asked Nov 29 '22 05:11

Rachel


1 Answers

If the arrays are unsorted then you must do a linear search to find the largest value in each. If the arrays are sorted then simply take the first or last element from each array (depending on the sort order).

like image 126
Andrew Hare Avatar answered Dec 10 '22 09:12

Andrew Hare