Monotonically Decreasing Function
A monotonically decreasing function is one whose value decreases as its input increases. That is, f(x+1) <= f(x) for all x in the domain.
Some examples:
reciprocal: f(x) = 1/x
negative logarithm: f(x) = ln(x)
nonpositive powers: f(x) = x^a, a > 0
Java example:


C++ example:


Python example:


Key properties:
 Function output decreases as input increases
 No increasing portions over domain
 Useful for modeling decay, attenuation, consumption
Monotonically decreasing functions appear in physics, statistics, economics to model declining quantities.
A function ( f(x) ) is said to be monotonically decreasing if for every pair ( x_1, x_2 ) such that ( x_1 < x_2 ), ( f(x_1) \geq f(x_2) ). This means the function does not increase as its input increases; it either stays the same or decreases. The same concept can apply to arrays, where each subsequent element is either the same as or smaller than the previous one.
Duplicates are allowed in a monotonically decreasing function or sequence. In the formal definition, the condition is ( f(x_1) \geq f(x_2) ) for ( x_1 < x_2 ), where the ( \geq ) symbol indicates that the function value can either decrease or stay the same as ( x ) increases. Therefore, duplicates do not violate the condition for a sequence or function to be monotonically decreasing.
Code Explanation
Java


In this Java code, we loop through the array starting from the second element. If we find an element greater than the previous one, the array is not monotonically decreasing.
C++


In the C++ code, we use a vector<int>
and iterate through it, checking that every subsequent element is less than or equal to the previous one.
Python


In Python, the structure is the same as in Java and C++. We loop through the list arr
and if we find an element that is greater than the previous, we return False
.
In each of these implementations, the use of the >
operator means arrays with duplicates will still be classified as monotonically decreasing. This adheres to the formal definition.