Various Algorithms - Tomekske/algorithms GitHub Wiki
This section contains various algorithms that don't fall under any classification
Find Max Value
The findMaxValue algorithm aims to find the maximum value within an array.
Pseudo Code
procedure findMaxValue(A: list)
if is_empty(A) then
return "Array is empty"
end if
maxVal = A[0] // Initialize the maximum value with the first element
for i = 1 to length(A) - 1 do
if A[i] > maxVal then
maxVal = A[i] // Update the maximum value
end if
end for
return maxVal // Return the maximum value found
end procedure
Complexity
Time Complexity
- Worst case: $O(n)$
- Average case: $O(n)$
- Best case: $O(1)$
Space Complexity
- Worst: $O(1)$
Pros and Cons
Pros:
- Simplicity: The findMaxValue algorithm is typically straightforward and easy to understand.
- Efficiency: Linear time complexity $O(n)$, efficient for moderately sized datasets.
Cons:
- Limited functionality: Solely on finding the maximum value.
- Lack of optimization: Not the most optimal solution for very large datasets. Other specialized algorithms or data structures, such as binary search trees or heaps, can offer faster maximum value retrieval for large collections of data.