Monotonically Increasing Function
A monotonically increasing function is one where the function’s value increases as the input increases. That is, f(x+1) >= f(x) for all x in the domain.
Some examples of monotonically increasing functions:
 Linear: f(x) = x
 Quadratic: f(x) = x^2
 Exponential: f(x) = e^x
Java example:


C++ example:


Python example:


Key properties:
 Output increases as input increases
 No decreasing portions over domain
 Useful for modeling growth, returns, scaling
Monotonically increasing functions are common in physics, finance, and statistics for quantities that grow over time.
The term “monotonic” comes from the word “monotone,” which implies a single, unchanging tone. In mathematics, a monotonic function is one that either never increases or never decreases as you move along the domain. The idea is that the function behaves in a single, unchanging mannerâ€”either always going up or always going down (or staying the same, which is considered consistent with the “unchanging” behavior).
Both “monotonically increasing” and “monotonically decreasing” functions adhere to this concept of having a single, unchanging direction. That’s why the term “monotonic” is used as a descriptor for both. It signals that the function has a consistent behavior over its domain, whether that’s always increasing, always decreasing, or staying constant.
A visual representation of a monotonic function will show a curve or line that moves in a single, unchanging direction when viewed from left to right along the xaxis. Here are some key visuals:
Monotonically Increasing Function: The curve or line will start at a lower point and move upwards as you go from left to right. It may stay flat for some segments but will never go down.
Monotonically Decreasing Function: The curve or line will start at a higher point and move downwards as you go from left to right. Similar to the increasing function, it may stay flat for some segments but will never go up.
In both cases, the function might flatten out (stay constant) for certain segments but will never reverse direction. If you were to draw a tangent line at any point along the curve, the angle of the tangent line would either be positive (for increasing), zero (for constant), or negative (for decreasing), and that would remain consistent across the entire function.
A function ( f(x) ) is said to be monotonically increasing if, for every ( x_1 < x_2 ), ( f(x_1) \leq f(x_2) ). In simple terms, as the input value ( x ) increases, the output value ( f(x) ) also increases or stays the same; it never decreases.
A monotonically increasing function can contain duplicates. The formal definition states ( f(x_1) \leq f(x_2) ) for ( x_1 < x_2 ), which allows for the possibility of ( f(x_1) = f(x_2) ). Therefore, in the context of an array, it means that adjacent or nonadjacent elements can be equal and the array can still be considered monotonically increasing.
In the code examples, the use of the <=
operator in the conditions would allow arrays with duplicates to be correctly identified as monotonically increasing.
Here is the code to check whether an array is monotonically increasing.
Java


C++


Python


In each code snippet, we loop through the array starting from the second element. We then compare each element to its predecessor. If we find an element that is smaller than its predecessor, we return false
immediately; otherwise, we return true
.