-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy paththeory.txt
More file actions
27 lines (14 loc) · 1 KB
/
theory.txt
File metadata and controls
27 lines (14 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Recusrion is an assumption, in which we know the answer of the subproblem & using that we try to find the solution of the main problem.
A function call itself is called Recusrion.
it is not a data structure instead it is a way to write a program.
Time and Space Complexity :-
Time Complexity :-
the time Complexity totally depends on the number of recursive calls your program made.
example :- a simple factorial program using Recusrion take O(n) time while
The time complexity of a recursive Fibonacci sequence (fib(n) = fib(n-1) + fib(n-2)) is O(2^n)
Space Complexity :-
space complexity refers to the amount of memory space used by the algorithm relative to the size of the input.
In recursion, space complexity is influenced by the stack space used for function calls and the recursive depth.
when the time complexity increases to O(2^n), then It can be optimized using dynamic programming.
This article is Contributed by Himanshu Jha.
Connect with me on linkedin https://www.linkedin.com/in/himanshujhaa/