Skip to content

Commit 43bcb2a

Browse files
adding all resources
0 parents  commit 43bcb2a

File tree

85 files changed

+5777
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+5777
-0
lines changed

1. Resources/BigO-cheat-sheet.pdf

28.5 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
1.05 MB
Binary file not shown.

1. Resources/DAA Syllabus.pdf

118 KB
Binary file not shown.

1. Resources/Interview cheatsheet.pdf

33.6 KB
Binary file not shown.

1. Resources/Master Plan.pdf

128 KB
Binary file not shown.

1. Resources/Master_the_Interview.pdf

26.7 KB
Binary file not shown.

2. Big-O/O(1).py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#O(1) - Constant Time
2+
#The no. of operations do not depend on the size of the input and are always constant.
3+
import time
4+
5+
array_small = ['nemo' for i in range(10)]
6+
array_medium = ['nemo' for i in range(100)]
7+
array_large = ['nemo' for i in range(10000)]
8+
9+
def finding_nemo(array):
10+
t0 = time.time()
11+
for i in array:
12+
pass
13+
t1 = time.time()
14+
print(f'Time taken = {t1-t0}')
15+
16+
finding_nemo(array_small)
17+
finding_nemo(array_medium)
18+
finding_nemo(array_large)
19+
20+
#Time taken in all 3 cases would be 0.0 seconds because we are only extracting the first and second elements of the arays.
21+
#We are not looping over the entire array.
22+
#We are performing two O(1) operations, which equal to O(2)
23+
#Any constant number can be considered as 1. There we can say this function is of O(1) - Constant Time Complexity.
24+

2. Big-O/O(m + n).py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import time
2+
3+
large1 = ['nemo' for i in range(100000)]
4+
large2 = ['nemo' for i in range(100000)]
5+
6+
def find_nemo(array1, array2):
7+
8+
#Here there are two different variables array1 and array2.
9+
#They have to be represented by 2 different variables in the Big-O representation as well.
10+
#Let array1 correspond to m and array2 correspond to n
11+
12+
t0 = time.time() #O(1)
13+
for i in range(0,len(array1)): #O(m)
14+
if array1[i] == 'nemo': #m*O(1)
15+
print("Found Nemo!!") #k1*O(1) where k1 <= m because this statement will be executed only if the if statement returns True, which can be k1(<=m) times
16+
t1 = time.time() #O(1)
17+
print(f'The search took {t1-t0} seconds.') #O(1)
18+
19+
t0 = time.time() #O(1)
20+
for i in range(0, len(array2)): #O(n)
21+
if array2[i] == 'nemo': #n*O(1)
22+
print("Found Nemo!!") #k2*O(1) where k2 <= m because this statement will be executed only if the if statement returns True, which can be k2(<=m) times
23+
t1 = time.time() #O(1)
24+
print(f'The search took {t1 - t0} seconds.') #O(1)
25+
26+
find_nemo(large1, large2)
27+
28+
#Total time complexity of the find_nemo function =
29+
#O(1 + m + m*1 + k1*1 + 1 + 1 + 1 + n + n*1 + k2*1 + 1 + 1) = O(6 + 2m + 2n + k1 + k2)
30+
#Now k1<=m and k2<=n. In the worst case, k1 can be m and k2 can be n. We'll consider the worst case and calculate the Big-O
31+
#O(6 + 2m + 2n + m + n) = O(3m + 3n + 6) = O(3(m + n + 2))
32+
#The constants can be safely ignored.
33+
#Therefore, O(m + n + 2) = O(m + n)

0 commit comments

Comments
 (0)