You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: TheMasterTheorem
+41-28
Original file line number
Diff line number
Diff line change
@@ -1,31 +1,35 @@
1
1
import math
2
+
import time
2
3
4
+
def typeOn(str):
5
+
#prints on the screen with a delay for the feeling of a typing animation
6
+
for char in str:
7
+
print(char, end="", flush=True)
8
+
time.sleep(0.01) #the waiting time between each char
9
+
3
10
def getRelation():
4
11
#The function gets from the user the a, b k and i parts of the recurrence relation.
5
12
#The function takes out a list that contains: a on its first element, b on its second element.
6
13
#f(n) is in format >> n^k ∙ (log(n))^i, so k on its third element and i on its fourth element.
7
14
#The fifth element is the full recurrence relation (for printing porpuses mainly).
8
15
relation = [0,0,0,0,0]
9
-
print("This program gets variables of the T(n) relation and determines the asymptotic running time of the algorithm.")
10
-
print("Your recurrence relation needs to be from the following form:\nT(n) = a∙T(n/b) + Θ(n^k∙(log n)^i).")
11
-
print("Notes:\na >= 1\nb > 1\nk >= 0\ni >= 0")
12
-
print("Please enter:")
16
+
typeOn("This program gets variables of the T(n) relation and determines the asymptotic running time of the algorithm.\nYour recurrence relation needs to be from the following form:\nT(n) = a∙T(n/b) + Θ(n^k∙(log n)^i).\nNotes:\na >= 1\nb > 1\nk >= 0\ni >= 0\nPlease enter:\n")
13
17
while True:
14
18
#keeps getting input until all four inputs are valid according to instructions.
15
19
try:
20
+
time.sleep(0.5)
16
21
relation[0] = float(input("a: "))
17
22
relation[1] = float(input("b: "))
18
23
relation[2] = float(input("k: "))
19
24
relation[3] = float(input("i: "))
20
25
#checking if one of the inputs is invalid
21
26
if relation[0] < 1 or relation[1] <= 1 or relation[2] < 0 or relation[3] < 0:
0 commit comments