-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprimes.py
64 lines (28 loc) · 998 Bytes
/
primes.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
54
55
56
57
58
59
60
61
62
63
64
def genPrimes(n):
"""Function receives an integer n and returns all prime numbers betweem integer n and 0"""
primes = []
numbers = [x for x in range(2,n)]
for i in numbers:
if isPrime(i):
primes.append(i)
return primes
def isPrime(n):
"""Function checks whether a number is prime"""
for i in range(2,n):
if n%(i) ==0:
return False
else:
return True
print genPrimes(10)
print isPrime(4)
"""
ASYMPTOTIC ANALYSIS
primes = [] ------------------------------------->bigO(1)
numbers = [x for x in range(2,n)] --------------->bigO(n)
for i in numbers:-------------------------------->bigO(n^2)
if isPrime(i):2 ----------------------------->bigO(1)
primes.append(i) ------------------------>bigO(1)
return primes ---------------------------------> bigO(1)
=======> bigO(1) + bigO(n) +bigO(n^2) + bigO(1) + bigO(1)
Answer=======> bigO(n^2)
"""