Finding the Smallest Element in an Array
Problem Statement
Given an array of integers, find the smallest (minimum) element in the array.
Example
- Test Cases:
- Input:
[1, 2, 3, 4, 5] | Output: 1
- Input:
[5, 4, 3, 2, 1] | Output: 1
- Input:
[-3, -5, -7, -2, -8, -1, -4] | Output: -8
- Input:
[100] | Output: 100
- Input:
[] | Output: undefined (Empty Array)
Conclusion
All methods discussed have a time complexity of O(n), but the space complexity varies. The brute force and built-in methods are more straightforward and efficient in terms of space, while the recursive method uses more space due to the recursive stack.