2019-02-26 in class
This commit is contained in:
parent
9548ae5e17
commit
57a4615e08
3 changed files with 101 additions and 0 deletions
30
heasy.py
Executable file
30
heasy.py
Executable file
|
@ -0,0 +1,30 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
|
||||
def histogram(A):
|
||||
m = min(A)
|
||||
|
||||
for e in A:
|
||||
negative = e < 0
|
||||
|
||||
if negative:
|
||||
for _ in range(m,e):
|
||||
print(" ", end="")
|
||||
for _ in range(e,0):
|
||||
print("#", end="")
|
||||
print("|")
|
||||
else:
|
||||
for _ in range(m,0):
|
||||
print(" ", end="")
|
||||
print("|", end="")
|
||||
for _ in range(0,e):
|
||||
print("#", end="")
|
||||
print("")
|
||||
|
||||
def main():
|
||||
args = [int(x) for x in sys.argv[1:]]
|
||||
histogram(args)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
24
min.py
Executable file
24
min.py
Executable file
|
@ -0,0 +1,24 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
|
||||
def minimum(a):
|
||||
l = len(a)
|
||||
|
||||
if l == 0:
|
||||
return None
|
||||
|
||||
m = a[0]
|
||||
for i in range(1, l):
|
||||
if a[i] < m:
|
||||
m = a[i]
|
||||
|
||||
return m
|
||||
|
||||
if __name__ == "__main__":
|
||||
A = []
|
||||
for line in sys.stdin:
|
||||
A.append(int(line))
|
||||
|
||||
print(minimum(A))
|
||||
|
47
notes.md
47
notes.md
|
@ -32,3 +32,50 @@ f(n) = O(g(n))
|
|||
*Definition:* if f(n) is such that f(n) = k * A(g(n)) for all _n_ sufficiently
|
||||
large and for some constant k > 0, then we say that
|
||||
|
||||
# Complexity notations (lecture 2019-02-26)
|
||||
|
||||
## Characterizing unknown functions
|
||||
|
||||
pi(n) = number of primes less than n
|
||||
|
||||
## First approximation
|
||||
|
||||
*Upper bound:* linear function
|
||||
|
||||
pi(n) = O(n)
|
||||
|
||||
*Lower bound:* constant function
|
||||
|
||||
pi(n) = omega(1)
|
||||
|
||||
*Non-trivial tight bound*:
|
||||
|
||||
pi(n) = theta(n/log n)
|
||||
|
||||
## Theta notation
|
||||
Given a functio ng(n), we define the __family__ of functions theta(g(n)) such
|
||||
that given a c_1, c_2 and an n_0, for all n >= n_0 g(n) is sandwiched between
|
||||
c_1g(n) and c_2g(n)
|
||||
|
||||
## Big omega notation
|
||||
Omega(g(n)) is a family of functions such that there exists a c and an n_0 such
|
||||
that for all n>= n_0 g(n) dominates c\*g(n)
|
||||
|
||||
## Big "oh" notation
|
||||
O(g(n)) is a family of functions such that there exists a c and an n_0 such
|
||||
that for all n>= n_0 g(n) is dominated by c\*g(n)
|
||||
|
||||
## Small "oh" notation
|
||||
o(g(n)) is the family of functions O(g(n)) excluding all the functions in
|
||||
theta(g(n))
|
||||
|
||||
## Small omega notation
|
||||
omega(g(n)) is the family of functions Omega(g(n)) excluding all the functions in
|
||||
theta(g(n))
|
||||
|
||||
## Recap
|
||||
*asymptotically* = <=> theta(g(n))
|
||||
*asymptotically* < <=> o(g(n))
|
||||
*asymptotically* > <=> omega(g(n))
|
||||
*asymptotically* <= <=> O(g(n))
|
||||
*asymptotically* >= <=> Omega(g(n))
|
||||
|
|
Reference in a new issue