Input: arr = [2, 3, 4, 1, 9, 5] Output: Largest Element: 9 Input: arr = [1, 7, 2] Output: Largest Element: 7
Find the largest Element in an Array Using Linear Search.
- Set a variable, initially holding the first element.
- Iterate through each element of the given array.
- For each element, compare it with the current maximum.
- If a larger element is found, update the maximum.
- Return the final maximum.
# Python code to find largest number of array def find_largest(arr): max_element = arr[0] # Linear Search for element in arr: if element > max_element: max_element = element return max_element arr = [2, 4, 9, 1] print("Largest Number:", find_largest(arr))
Largest Number: 9- Time Complexity: O(n) where n is the number of elements present in the array.
- Space Complexity: O(1) as no extra space is required to solve this problem.
Find the largest Element in an Array Using max() Function.
# Python code to find largest number of array using max() def find_largest(arr): return max(arr) arr = [2, 4, 9, 10, 3] print("Largest Number:", find_largest(arr))
Largest Number: 10- Time Complexity: O(n) where n is the size of the given array
- Space Complexity: O(1) as no extra space is required.





Trends is an amazing magazine Blogger theme that is easy to customize and change to fit your needs.