The time complexity, in Big O notation, for each function:


int recursiveFun1(int n)
{
    if (n <= 0)
        return 1;
    else
        return 1 + recursiveFun1(n-1);
}

This function is being called recursively n times before reaching the base case so its O(n), often called linear.


int recursiveFun2(int n)
{
    if (n <= 0)
        return 1;
    else
        return 1 + recursiveFun2(n-5);
}

This function is called n-5 for each time, so we deduct five from n before calling the function, but n-5 is also O(n). (Actually called order of n/5 times. And, O(n/5) = O(n) ).


int recursiveFun3(int n)
{
    if (n <= 0)
        return 1;
    else
        return 1 + recursiveFun3(n/5);
}

This function is log(n) base 5, for every time we divide by 5 before calling the function so its O(log(n))(base 5), often called logarithmic and most often Big O notation and complexity analysis uses base 2.


void recursiveFun4(int n, int m, int o)
{
    if (n <= 0)
    {
        printf("%d, %d\n",m, o);
    }
    else
    {
        recursiveFun4(n-1, m+1, o);
        recursiveFun4(n-1, m, o+1);
    }
}

Here, it's O(2^n), or exponential, since each function call calls itself twice unless it has been recursed n times.



int recursiveFun5(int n)
{
    for (i = 0; i < n; i += 2) {
        // do something
    }

    if (n <= 0)
        return 1;
    else
        return 1 + recursiveFun5(n-5);
}

And here the for loop takes n/2 since we're increasing by 2, and the recursion takes n/5 and since the for loop is called recursively, therefore, the time complexity is in

(n/5) * (n/2) = n^2/10,

due to Asymptotic behavior and worst-case scenario considerations or the upper bound that big O is striving for, we are only interested in the largest term so O(n^2).


Good luck on your midterms ;)

Answer from coder on Stack Overflow
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ dsa โ€บ how-to-analyse-complexity-of-recurrence-relation
Time Complexity Analysis of Recursive Functions - GeeksforGeeks
The time complexity of this function is written as T(n) = 2T(n/2) + O(n). Now to find the time complexity, we need to solve this recurrence. There are mainly three common methods used to solve recurrence relations that arise in the analysis ...
Published: March 7, 2026
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ dsa โ€บ how-to-solve-time-complexity-recurrence-relations-using-recursion-tree-method
Recursion Tree Method to Solve Recurrences - GeeksforGeeks
January 11, 2026 - The recursion tree method is used to analyze the time complexity of recursive algorithms by visually representing the recurrence as a tree. Each node of the tree represents the work done in a single recursive call, and each level represents one stage of the recursion.
Discussions

Time complexity of recursive Fibonacci program
Your All-in-One Learning Portal. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions. More on geeksforgeeks.org
๐ŸŒ geeksforgeeks.org
1
October 20, 2017
recursion - Determining complexity for recursive functions (Big O notation) - Stack Overflow
I have a Computer Science Midterm tomorrow and I need help determining the complexity of these recursive functions. I know how to solve simple cases, but I am still trying to learn how to solve these More on stackoverflow.com
๐ŸŒ stackoverflow.com
How to calculate the time complexities of recursive functions ??
Master Theorem. Specifically, it depends on how much โ€œworkโ€ is left after each recursion, and how that work is distributed. For example take binary search. Let T(n) be the total amount of work needed on an array of size n. Then we have the recursive relation T(n) =T(n/2)+1. This comes from each recursion halving the relevant array size, and the +1 is the comparator to see which half of the array we are in. Now that we have the recursive relation, the master theorem tells us T(n)=log(n). More on reddit.com
๐ŸŒ r/algorithms
14
17
April 15, 2021
Why is recursion so praised despite it typically using more memory and not being any faster than iteration?
Because there are times when it's clearer to define an algorithm recursively than iteratively, and it can be cleaner in the theoretical sense (less explicit tracking of state, for example). Consider looping through the nodes of a tree. In a recursive algorithm, the state of your search is stored in the call stack. With an iterative approach, you may have to use a structure like a stack to store which nodes to visit next. It's doable, but not as pretty. More on reddit.com
๐ŸŒ r/AskComputerScience
31
47
February 27, 2020
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ dsa โ€บ time-complexity-analysis-tower-hanoi-recursion
Time Complexity Analysis | Tower Of Hanoi (Recursion) - GeeksforGeeks
February 15, 2023 - The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules: 1) Only one disk can be moved at a time. 2) Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack i.e.
Top answer
1 of 7
595

The time complexity, in Big O notation, for each function:


int recursiveFun1(int n)
{
    if (n <= 0)
        return 1;
    else
        return 1 + recursiveFun1(n-1);
}

This function is being called recursively n times before reaching the base case so its O(n), often called linear.


int recursiveFun2(int n)
{
    if (n <= 0)
        return 1;
    else
        return 1 + recursiveFun2(n-5);
}

This function is called n-5 for each time, so we deduct five from n before calling the function, but n-5 is also O(n). (Actually called order of n/5 times. And, O(n/5) = O(n) ).


int recursiveFun3(int n)
{
    if (n <= 0)
        return 1;
    else
        return 1 + recursiveFun3(n/5);
}

This function is log(n) base 5, for every time we divide by 5 before calling the function so its O(log(n))(base 5), often called logarithmic and most often Big O notation and complexity analysis uses base 2.


void recursiveFun4(int n, int m, int o)
{
    if (n <= 0)
    {
        printf("%d, %d\n",m, o);
    }
    else
    {
        recursiveFun4(n-1, m+1, o);
        recursiveFun4(n-1, m, o+1);
    }
}

Here, it's O(2^n), or exponential, since each function call calls itself twice unless it has been recursed n times.



int recursiveFun5(int n)
{
    for (i = 0; i < n; i += 2) {
        // do something
    }

    if (n <= 0)
        return 1;
    else
        return 1 + recursiveFun5(n-5);
}

And here the for loop takes n/2 since we're increasing by 2, and the recursion takes n/5 and since the for loop is called recursively, therefore, the time complexity is in

(n/5) * (n/2) = n^2/10,

due to Asymptotic behavior and worst-case scenario considerations or the upper bound that big O is striving for, we are only interested in the largest term so O(n^2).


Good luck on your midterms ;)

2 of 7
153

For the case where n <= 0, T(n) = O(1). Therefore, the time complexity will depend on when n >= 0.

We will consider the case n >= 0 in the part below.

1.

T(n) = a + T(n - 1)

where a is some constant.

By induction:

T(n) = n * a + T(0) = n * a + b = O(n)

where a, b are some constant.

2.

T(n) = a + T(n - 5)

where a is some constant

By induction:

T(n) = ceil(n / 5) * a + T(k) = ceil(n / 5) * a + b = O(n)

where a, b are some constant and k <= 0

3.

T(n) = a + T(n / 5)

where a is some constant

By induction:

T(n) = a * log5(n) + T(0) = a * log5(n) + b = O(log n)

where a, b are some constant

4.

T(n) = a + 2 * T(n - 1)

where a is some constant

By induction:

T(n) = a + 2a + 4a + ... + 2^(n-1) * a + T(0) * 2^n 
     = a * 2^n - a + b * 2^n
     = (a + b) * 2^n - a
     = O(2 ^ n)

where a, b are some constant.

5.

T(n) = n / 2 + T(n - 5)

where n is some constant

Rewrite n = 5q + r where q and r are integer and r = 0, 1, 2, 3, 4

T(5q + r) = (5q + r) / 2 + T(5 * (q - 1) + r)

We have q = (n - r) / 5, and since r < 5, we can consider it a constant, so q = O(n)

By induction:

T(n) = T(5q + r)
     = (5q + r) / 2 + (5 * (q - 1) + r) / 2 + ... + r / 2 +  T(r)
     = 5 / 2 * (q + (q - 1) + ... + 1) +  1 / 2 * (q + 1) * r + T(r)
     = 5 / 4 * (q + 1) * q + 1 / 2 * (q + 1) * r + T(r)
     = 5 / 4 * q^2 + 5 / 4 * q + 1 / 2 * q * r + 1 / 2 * r + T(r)

Since r < 4, we can find some constant b so that b >= T(r)

T(n) = T(5q + r)
     = 5 / 2 * q^2 + (5 / 4 + 1 / 2 * r) * q + 1 / 2 * r + b
     = 5 / 2 * O(n ^ 2) + (5 / 4 + 1 / 2 * r) * O(n) + 1 / 2 * r + b
     = O(n ^ 2)
๐ŸŒ
Codeforces
codeforces.com โ€บ blog โ€บ entry โ€บ 118843
Recursion and Backtracking - Codeforces
โ€ข Print all subsets of a given vector. Time complexity of Recursive Brute-Force โ€ข Can be calculated as the number of recursive calls multiplied by additional complexity of the function.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ dsa โ€บ program-for-nth-fibonacci-number
Nth Fibonacci Number - GeeksforGeeks
Time Complexity: O(2n), because each state requires answers from previous two states, and thus calls the function for both of those states recursively.
Published: April 2, 2026
Find elsewhere
๐ŸŒ
Medium
tarunjain07.medium.com โ€บ complexity-analysis-for-recursion-notes-cd4930e26683
Complexity analysis for recursion โ€” [Notes] | by Tarun Jain | Medium
January 14, 2025 - The recursion tree has logn + 1 levels, each costing cn. So the total cost = cn * (logn + 1) = cnlogn + cn. After ignoring the low-order term and the constant c in (cnlogn + cn), the time complexity of merge sort = O(nlogn).
๐ŸŒ
YourBasic
yourbasic.org โ€บ algorithms โ€บ time-complexity-recursive-functions
Time complexity of recursive functions [Master theorem] ยท YourBasic
T(n) = 1 + T(n/2), when n > 1. (**) The equation (**) captures the fact that the function performs constant work (thatโ€™s the one) and a single recursive call to a slice of size n/2.
๐ŸŒ
JavaScript in Plain English
javascript.plainenglish.io โ€บ recursive-algorithms-and-their-time-complexities-o-n-vs-2-n-713856ad4e2
Recursive Algorithms and Their Time Complexities O(n) vs O(2^n) | by Code Ceeker | JavaScript in Plain English
June 13, 2023 - Hence, we can see, that we get 4 function calls for a factorial of 4 in the above example. In every function call, we have a constant time, we do not have any loop in our function. Hence, we can write it as below. T = O(1) => Time complexity of a single function call
๐ŸŒ
Launch School
launchschool.com โ€บ books โ€บ advanced_dsa โ€บ read โ€บ time_and_space_complexity_recursive
Analyzing Time and Space Complexity in Recursive Algorithms
By examining the structure of the recursive tree, we can count the number of nodes (representing function calls) and determine the number of operations performed in each call. This allows us to estimate the algorithm's overall time complexity.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ dsa โ€บ how-to-analyse-loops-for-complexity-analysis-of-algorithms
Analysis of Loops in Algorithms - GeeksforGeeks
A loop or recursion that runs a constant number of times is also considered O(1). For example, the following loop is O(1). ... The Time Complexity is O(n) if the loop variables are incremented/decremented by a constant amount.
Published: January 29, 2026
๐ŸŒ
Enjoy Algorithms
enjoyalgorithms.com โ€บ blog โ€บ time-complexity-analysis-of-recursion-in-programming
Analysis of Recursion in Data Structures and Algorithms
We are reversing n-size array by ... recursion, the input size decreases by 2. Time complexity T(n) = Time complexity of solving an (n - 2) size problem + Time complexity of the swapping operation = T(n - 2) + O(1)....
๐ŸŒ
Medium
medium.com โ€บ nerd-for-tech โ€บ practically-understanding-time-complexities-of-recursive-and-iterative-functions-95238525c145
Practically understanding time complexities of Recursive and Iterative functions
May 30, 2021 - In the recursive algorithm the if statement takes constant time but the time taken by the recursive statement (recursivefib(n โ€” 1) + recursivefib(n โ€” 2) ) depends on the inputโ€ฆ
๐ŸŒ
Dot Net Tutorials
dotnettutorials.net โ€บ home โ€บ time complexity of recursive function
Time Complexity of Recursive Function - Dot Net Tutorials
March 20, 2021 - There is one more method to find the time complexity i.e. using recurrence relation. Let us see how to write a recurrence relation and how to solve it to find the time complexity of the recursive function.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ dsa โ€บ short-notes-on-recursion-and-backtracking
Short Notes on Backtracking - GeeksforGeeks
February 28, 2026 - Recurse with that choice. If it leads to a solution, keep it; else undo (backtrack) and try the next option. ... This problem generates all possible subsets of a given array. ... This problem generates all possible arrangements of elements. First position โ†’ n choices, second โ†’ n-1, and so on ... Space Complexity depends on recursion depth.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ dsa โ€บ recursion-algorithms
Recursive Algorithms - GeeksforGeeks
Recursion is a technique used in computer science to solve big problems by breaking them into smaller, similar problems. The process in which a function calls itself directly or indirectly is called recursion and the corresponding function is called a recursive function.
Published: January 20, 2026
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ dsa โ€บ recurrence-relations-a-complete-guide
Recurrence Relations - GeeksforGeeks
January 17, 2026 - A recurrence relation is a mathematical expression that defines a sequence in terms of its previous terms. In the context of algorithmic analysis, it is often used to model the time complexity of recursive algorithms.