VOOZH about

URL: https://www.geeksforgeeks.org/dsa/program-to-find-largest-element-in-an-array/

⇱ Largest element in an Array - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Largest element in an Array

Last Updated : 30 Jan, 2026

Given an arr[] of elements of size n, return the largest element given in the array.

Examples:

Input: arr[] = [10, 20, 4]
Output: 20
Explanation: Among 10, 20 and 4, 20 is the largest. 

Input: arr[] = [20, 10, 20, 4, 100]
Output: 100

Iterative Approach - O(n) Time and O(1) Space

Traverse the entire array and keep track of the largest element encountered. Update the maximum value whenever a larger element is found, and after scanning all elements, the stored value represents the largest element in the array.


Output
100

Recursive Approach - O(n) Time and O(n) Space

The idea is similar to the iterative approach. Here the traversal of the array is done recursively instead of an iterative loop. 


Output
100

Using Library Methods - O(n) Time and O(1) Space

Most of the languages have a relevant max() type in-built function to find the maximum element, such as  std::max_element in C++. We can use this function to directly find the maximum element.  


Output
100
Comment