![]() |
VOOZH | about |
Given an array, we need to find the largest element in it.
For example:
Input : arr[] = {20, 10, 20, 4, 100}
Output : 100
Let's explore different methods to find the largest element:
Python has an inbuilt method max() which returns the maximum value among the arguments.
9808
This method manually traverse the array and update the largest element when a bigger element is found.
9808
The reduce() function from functools can find the largest element by applying max cumulatively across the array.
9808
Here sort() function is used to sort the array. The largest element will be the last element of the sorted array.
9808
Please refer complete article on Program to find largest element in an array for more details!
Use the operator.gt() function to compare elements and find the largest element iteratively.
7
Explanation: