From 57a4615e0888d2e6f02e11de86e8bbc7a535791a Mon Sep 17 00:00:00 2001 From: Claudio Maggioni Date: Tue, 26 Feb 2019 12:25:18 +0100 Subject: [PATCH] 2019-02-26 in class --- heasy.py | 30 ++++++++++++++++++++++++++++++ min.py | 24 ++++++++++++++++++++++++ notes.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100755 heasy.py create mode 100755 min.py diff --git a/heasy.py b/heasy.py new file mode 100755 index 0000000..c5d23ee --- /dev/null +++ b/heasy.py @@ -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() diff --git a/min.py b/min.py new file mode 100755 index 0000000..7d753af --- /dev/null +++ b/min.py @@ -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)) + diff --git a/notes.md b/notes.md index f2cac81..f48e18e 100644 --- a/notes.md +++ b/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))