-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXerY.py
53 lines (42 loc) · 1.53 KB
/
XerY.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# This Python file uses the following encoding: utf-8
import math
def log(a):
log_version = 2
return math.log(a, log_version)
# defining n to some random large number (to compute results)
n = 123
# Compare run-times using asymptotic notation
def c1(x, y):
# x er O(y)
print("Case 1: x er O(y)")
print(str(x)+" er <=("+str(y)+"): " + str(x <= y) + "\n")
#if (x+y < n and x < 50 and y < 50): # X and Y are MOST LIKELY constants, e.g. "x = 4, y = 3"
# print(str(x)+" er <=("+str(y)+"): TRUE, (both constant time)")
#else: # do original func
# print(str(x)+" er <=("+str(y)+"): " + str(x <= y) + "\n")
def c2(x, y):
# x er Ω(y) --- \u03A9
print("Case 2: x er Omega(y)")
print(str(x)+" er >=("+str(y)+"): " + str(x >= y) + "\n")
def c3(x, y):
# x er ϴ(y) --- \u03F4
print("Case 3: x er Theta(y)")
print(str(x)+" er =("+str(y)+"): " + str(x == y) + "\n")
def c4(x, y):
# x er o(y)
print("Case 4: x er o(y)")
print(str(x)+" er <("+str(y)+"): " + str(x < y) + "\n")
def c5(x, y):
# x er ω(y) --- \u03C9
print("Case 5: x er w(y)")
print(str(x)+" er >("+str(y)+"): " + str(x > y) + "\n")
# Noter:
# - "kvadratrod(x)" er "math.sqrt(x)"
# - "n^2" er "n**2"
# - Konstanter "(1,2,3...)" har altid samme voksehastighed! De er altid lavest voksehastighed i forhold til andre!
# OUTPUT:
c1(n**(1/4), n**(1/3)) # x er O(y) --- Konstanter (1,2,3...) er altid = TRUE, (konstant voksehastighed)!
#c2(x, y) # x er Ω(y)
#c3(x, y) # x er ϴ(y)
#c4(x, y) # x er o(y)
#c5(x, y) # x er ω(y)