4
4
- Bubble Sort
5
5
- Binary Search
6
6
7
- -------------------------------------------------------------------
7
+ What is Recurrence Relation ?
8
+ - In mathematics, a recurrence relation is an equation that expresses the nth term of a sequence as
9
+ a function of the k preceding terms, for some fixed k (independent from n), which is called
10
+ the order of the relation.
11
+
12
+ - A recurrence relation is an equation that defines a sequence based on a rule that gives the
13
+ next term as a function of the previous term(s).
14
+
15
+ Eg: Factorial Representation:
16
+ n!=n(n-1)! ; n>0
17
+ (To find the further values we have to expand the factorial notation,
18
+ where the succeeding term is dependent on the preceding one.)
19
+
20
+ Fibonacci Numbers:
21
+ Fn = Fn-1 + Fn-2
22
+
23
+ Reference- https://byjus.com/maths/recurrence-relation/
24
+
25
+
26
+ ----------------------------------------------------------------------------------------------------
8
27
// bubble sort
9
28
_________________
10
29
Array: |_|_|_|_|_|_|_|_|_|
31
50
T(3) = k*(3) + T(2)
32
51
T(2) = k*(2) + T(1)
33
52
T(1) = k*(1) + 0
34
- ---------------------------- // By adding all the above equations, we can get the total time
53
+ ---------------------------- // By adding all the above equations on both sides & cancellation , we can get the total time
35
54
T(n) = k*n + k*(n-1) + k*(n-2) + ...... + k*(1)
36
55
= k*(n + n-1 + n-2 + ..... 3 + 2 + 1)
37
56
= _k*_n*(n-1)_
41
60
Time Complexity = O(n^2)
42
61
43
62
44
- -------------------------------------------------------------------
63
+ ----------------------------------------------------------------------------------------------------
45
64
// binary search
46
65
_________________
47
66
Array: |_|_|_|_|_|_|_|_|_| size = n
76
95
= O(logn)
77
96
78
97
Time Complexity = O(logn)
79
-
98
+
99
+
100
+ ----------------------------------------------------------------------------------------------------
101
+ Reference - [Recurrence Relation (T(n)= T(n-1) + 1) #1] https://www.youtube.com/watch?v=4V30R3I1vLI
102
+ (Abdul Bari) [Recurrence Relation (T(n)= T(n-1) + n) #2] https://www.youtube.com/watch?v=IawM82BQ4II
103
+ [Recurrence Relation [ T(n)= 2T(n/2) +n] #3] https://www.youtube.com/watch?v=1K9ebQJosvo
104
+ [Recurrence Relation T(n)=2 T(n-1)+1 #4] https://www.youtube.com/watch?v=JvcqtZk2mng
105
+
106
+ [Recurrence Relation Dividing Function T(n)=T(n/2)+1 #1] https://www.youtube.com/watch?v=8gt0D0IqU5w
107
+ [Recurrence Relation Dividing [ T(n)=T(n/2)+ n]. #2] https://www.youtube.com/watch?v=XcZw01FuH18
108
+ [Recurrence Relation [ T(n)= 2T(n/2) +n] #3] https://www.youtube.com/watch?v=1K9ebQJosvo
80
109
*/
0 commit comments