Algorithmic Complexity and Probability Flashcards

1
Q

What is the trade off when deciding which option for a program is the most efficient?

A

Time and space efficiency:

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How to evaluate efficiency of programs?

A
  • measure with a timer
  • count the operations
  • abstract notion of order of growth (most appropriate way)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How can you time a program?

A

Use a time module:
import time t0 = time.clock (start)
call function
t1 = time.clock() - t0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the drawbacks of timimng programs?

A

Timing is inconsistent:

timer varies for different inputs but cannot really express a relationship between inputs and timer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the positive aspects and drawbacks of counting operations?

A

good:
count depends on algorithm
count is independent of the computer

bad:
count depends on the implementation
no clear definition of which operation to use

Overall: count varies for different inputs and can come up with a relationship between inputs and counts

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are the problems about timing and counting as evaluation implementations?

A

What oyu really want to do is evaluate the algorithm, scalability and the input isze

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Does the input influence how the function runs?

A

Yes, i.e. a function that searches for an element in a list:
1. when e is the first element in the lest –> best case
when e is not in the list –> worst case
want to measure this in a general way
(look through half for the average case)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What measure do we use to measure the order of growthß

A

Big OH notation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does the big o notation measure?

A

The upper bound of the asymptotic growth, often called order of growth
–> big o is used to descrive worst case as it is the bottleneck when a program runs
this evaluates the algorithm and not the machine or implementation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does O(N) measure?

A

–> how the time needed grows with the input growth

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What types of orders of growth do we know?

A
Constant
linear
quadratic
logarithmic
n log n
exponential
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the law of addition for o()?

A

O(f(n)) + O(g(n)) = O(f(n) + g(n))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the law of multiplication for O()?

A

O8f(n)) * O(g(n)) = O(f(n) * g(n))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What complexity classes do we know and what do they mean?

A

O(1) –> constant running time
O(log n) –> logarithmic running time
O(n) –> denotes linear running time
O(n log n) –> denotes log-linear running time
O(nC) –> polynominial runnung rime (c constant)
O(cN) –> exponential running time (c is a constant being raised to power based on soze if input)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are examples of constant complexity?

A
  • -> Complexity independent of input

examples: finding length of a list in python

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are examples of linear complexity?

A

Simple iterative loop algorithms are typically linear in complexity?
- i.e. linear seach on unsorted list

17
Q

What are examples of quadratic complexity?

A

determine if one list is a subset of another list

18
Q

What are examples of logarithmic complexity?

A

complexity grows as log of size of its inputs

i.e. bisection search

19
Q

What are examples of exponential complexity?

A

recursive functions where more than one recursive call for each size of problem

20
Q

What do we use big oh for?

A

To compare efficiency of algorithms

  • > notation that describes growth
  • > lower order of growth is better
  • > independent of machine specific implementation

Use big oh:

  • to descrive order of growt
  • upper bound
  • worst case analysis
21
Q

What is a sample space?

A

The set of all possible outcomes of a random process or experiment an event is a subset of a sample space

22
Q

What is the equally likely probability formula?

A
S = finites sample space and E is an event in S
P(E) = # of otcomes in E/ # of outcomes in S
23
Q

What is the multiplication rule (probability trees)

A

if an operation consists of k steps and the first step can be performed in n1 ways and the second step in n2 ways …. the entire operation can be performed in n1n2…nk ways

24
Q

What is a permutation?

A

A permutation of a set of objects is an ordering of the objects in a row. for example the set fo elements a, b, c has six permutations:
abc acb cba bca cab

25
Q

How to calculate the number of permutations?

A

n and r are integers and 1 <= r <= n the the number of r permutations of a set of n elements r permutations
P(n, r) = n!/(n-r)!

26
Q

what does
n
r n choose r denote?

A

The number of subsets of size r that can be chosen from a set of n elements

27
Q

How do you calculate the number of subsets of size r that can be chosen from a set of n elements
n
r

A

n
r
= n!/ r!(n-r)!

28
Q

What are the probability axioms?

A
For all events A and B in S: 
1. 0 <= P(A) <= 1
2. P(leere menge= 0 P (S) =1 
3. If A and B are disjoint then the probability of the union of A and B is 
P(A) + P(B)
29
Q

What is the likelihood of the compliment of an event?

A

P(Ac) = 1- P(A)

30
Q

How do you calculate the expected value of an experiment?

A

a1, …, an are the outcomes of the experiment and p1, …, pn are their respective probabilities:
= a1p1 + … + anpn

31
Q

How do you calculate Conditional probability of B given A?

A

P(B|A) = P(a n B)/ P(A)