Skip to content

Commit 7ae7ab2

Browse files
committed
minor updates
1 parent 1aa7bf4 commit 7ae7ab2

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

22_space_time_complexity_analysis/08_time_complexity_using_recurrence_method.cpp

+33-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,26 @@
44
- Bubble Sort
55
- Binary Search
66
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+
----------------------------------------------------------------------------------------------------
827
// bubble sort
928
_________________
1029
Array: |_|_|_|_|_|_|_|_|_|
@@ -31,7 +50,7 @@
3150
T(3) = k*(3) + T(2)
3251
T(2) = k*(2) + T(1)
3352
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
3554
T(n) = k*n + k*(n-1) + k*(n-2) + ...... + k*(1)
3655
= k*(n + n-1 + n-2 + ..... 3 + 2 + 1)
3756
= _k*_n*(n-1)_
@@ -41,7 +60,7 @@
4160
Time Complexity = O(n^2)
4261
4362
44-
-------------------------------------------------------------------
63+
----------------------------------------------------------------------------------------------------
4564
// binary search
4665
_________________
4766
Array: |_|_|_|_|_|_|_|_|_| size = n
@@ -76,5 +95,15 @@
7695
= O(logn)
7796
7897
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
80109
*/

misc/QnA.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -155,20 +155,23 @@ Q8: Difference between an Arithmetic and Geometric Progressions
155155
Commenly used AP, GP sequences?
156156
157157
S8: - Sum of the First n Positive Integers
158-
S(n) ​= 1+2+3+4+.....+n = __n*(n+1)__
158+
S(n) ​= 1+2+3+4+.....+n = __n*(n+1)__ = O(n^2)
159159
2
160160
161161
- Sum of the Squares of the First n Positive Integers
162-
S(n) ​= 1+4+9+16+...+n^2 = __n*(n+1)*(2n+1)__
162+
S(n) ​= 1+4+9+16+...+n^2 = __n*(n+1)*(2n+1)__ = = O(n^3)
163163
6
164164
165165
- Sum of the Cubes of the First n Positive Integers
166-
S(n) ​= 1+8+27+64+...+n^3 = __n^2_*_(n+1)^2__
166+
S(n) ​= 1+8+27+64+...+n^3 = __n^2_*_(n+1)^2__ = O(n^4)
167167
4
168168
169-
- Sequence [1 + 1/2 + 1/3 + 1/4 + .. + 1/n] = logn
169+
- Sequence [1 + 1/2 + 1/3 + 1/4 + .. + 1/n] = logn = O(logn)
170170
171-
- Sequence [(1+2+4+8+16+ ..... 2^(n-1)] = _(2^(n-1)_-_1)__
171+
- sum of 1 +1/2 + 1/4 + 1/8 + 1/16 … infinity = 2
172+
[1 +0.5 + 0.25 +0.125+ ...eventually adds up to 2 ]
173+
174+
- Sequence [(1+2+4+8+16+ ..... 2^(n-1)] = _(2^(n-1)_-_1)__ = O(2^n)
172175
n-1
173176
[Above sequence is calculated by formula: Sum of n terms in Geometric Progressions]
174177

0 commit comments

Comments
 (0)