Strictly Decreasing Function

A strictly decreasing function is one where f(x+1) < f(x) for all x in the domain. That is, the function output decreases as the input increases.

Some examples of strictly decreasing functions:

  • Reciprocal: f(x) = 1/x
  • Negative exponential: f(x) = e^-x
  • Negative power: f(x) = x^-a, a > 0

Java example:

1
2
3
4
5
6
// Exponential decay
double f(double x) {
  return Math.exp(-2*x); 
}

// Output strictly decreases as x increases

C++ example:

1
2
3
4
5
6
// Reciprocal 
double f(double x) {
  return 1.0 / x;
}

// Strictly decreasing function

Python example:

1
2
3
4
5
6
7
# Negative logarithm
import math

def f(x):
  return -math.log10(x)

# Values always decrease as x increases  

Key properties:

  • Output always decreases with increased input
  • No increasing portions
  • Useful for modeling decay

Strictly decreasing functions model quantities that decay or attenuate consistently. Appear in physics, engineering, statistics.

A strictly decreasing function is one where, for any two distinct points ( x_1 ) and ( x_2 ), if ( x_1 < x_2 ), then ( f(x_1) > f(x_2) ). In simpler terms, as you move from left to right on the graph, the function values go down. Duplicates are not allowed in the output; each value must be strictly less than the previous value.

Explain the Code

Java

1
2
3
4
5
6
7
8
public static boolean isStrictlyDecreasing(int[] arr) {
  for (int i = 1; i < arr.length; i++) {
    if (arr[i] >= arr[i-1]) {
      return false;
    }
  }
  return true;
}

Here, we iterate through the array arr. If any element is greater than or equal to its preceding element, the function returns false. Otherwise, it returns true.

C++

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#include <iostream>
#include <vector>
using namespace std;

bool isStrictlyDecreasing(vector<int> arr) {
  for (int i = 1; i < arr.size(); i++) {
    if (arr[i] >= arr[i-1]) {
      return false;
    }
  }
  return true;
}

Same logic as in Java. We loop through the array and check each adjacent pair of elements.

Python

1
2
3
4
5
def is_strictly_decreasing(arr):
    for i in range(1, len(arr)):
        if arr[i] >= arr[i-1]:
            return False
    return True

Again, the same logic is applied. Iterate through the list arr and compare adjacent elements.

In all three languages, the function returns a boolean value indicating whether the array is strictly decreasing or not.