Algorithmic Complexity and Probability Flashcards

1
Q

One way to measure how long a program takes to run is by timing it. But that would not be particularly informative, because the result would depend upon:

A
  • the speed of the computer
  • the efficiency of the Python implementation on that machine
  • the value of the input
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How can one evaluate the efficiency of programs? (3 ways)

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

States some downsides of timing programs.

A

Time does vary between algorithms, but it does not vary between implementations and computers

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

Downsides of counting operations?

A

Counting depends on the algorithm, but it does not depend on implementations, and there is no clarity in which operations to count.

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

Let’s say that we want to evaluate a function and we want to express efficiency in terms of size of input:

for i in L:
if i == e;
return True
return False

Analyze the first, worst and the average case scenarios in this case.

A

BEST CASE: first element is e
- minimum running time over all possible inputs of a given size, len(L)

AVERAGE CASE: look through about half of the elements of the list
- average running time over all possible inputs

WORST CASE: element e is not in the list
- maximum running time over all possible inputs of a given size, len(L)

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

What does “Big Oh” measure?

A

Big Oh measures the asymptotic growth, often called the order of growth.

Describes how the amount of time needed grows as size of the (input to) problem grows.

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

Big Oh is used to describe the ______ case.

a. best
b. worst
c. average

A

b. worst

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

Big Oh expresses the rate of growth of the program relative to the input size. True or false?

A

True

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

Big Oh evaluates the algorithm, the machine and the implementation. True or False?

A

False

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

What running times do the following denote?

a. O(1)
b. O(logn)
c. O(n)
d. O(nlogn)
e. O(nˆc)
f. O(cˆn)

A

a. the constant running time
b. the logarithmic running time
c. the linear running time
d. the log-linear running time
e. the polynomial running time (c is a constant)
f. the exponential running time (c is a constant being raise to a power based on the size of the input)

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

Rank the algorithm orders based on their time to execute:

O(1)
O(logn)
O(n)
O(nlogn)
O(nˆc)
O(cˆn)
A

They are in perfect order.

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

The constant complexity is dependent on input. True or false?

A

False.

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

Simple iterative loop algorithms are typically linear in complexity. True or false?

A

True

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

Nested loops describe quadratic complexity. True or false?

A

True

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

Bisection search is an example of quadratic complexity. True or false?

A

False, bisection search is an example of logarithmic complexity.

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

By the way, this is what the bisection method it. Click

A

the bisection method is a root-finding method that applies to any continuous functions for which one knows two values with opposite signs. The method consists of repeatedly bisecting the interval defined by these values and then selecting the subinterval in which the function changes sign, and therefore must contain a root. It is a very simple and robust method, but it is also relatively slow. Because of this, it is often used to obtain a rough approximation to a solution which is then used as a starting point for more rapidly converging methods

17
Q

When talking about probability, what is a sample space?

A

A sample space is the set of all possible outcomes of a random process or experiment.

18
Q

When talking about probability, what is an event?

A

An event is a subset of a sample space.

19
Q

State the Equally Likely Probability formula.

A

P = (the number of outcomes in the event)/(the number of outcomes in the sample space)

20
Q

What are permutations?

A

Permutation is the process of ordering a set of objects.

An r-permutation of a set of n elements is an ordered selection of r elements taken from the set of n elements.

21
Q

What is the formula of permutations?

A

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

22
Q

What are combinations?

A

Combination is the process of combining a set of objects in different ways.

An r-combination of a set of n elements is a subset of r of the n elements.

23
Q

What is the formula of combinations?

A

C(n, r) = n! / r! * (n - r)!

24
Q

Can you express the combination formula based on the permutation formula?

A

Yes.

C(n , r) = P (n , r) / r!

25
Q

What is P(Ø) equal to?

A

0

26
Q

What is the probability of a sample space?

A

1

27
Q

A probability is always between 0 and 1. True or false?

A

True

28
Q

Briefly explain conditional probability.

A

If A and B are events in a sample space, then the conditional probability of B given A is
P(B|A) = P(A intersect B) / P(A)

when P(A) != 0

29
Q

Can you say anything about Bayes’ Theorem?

A

Bayes’ theorem (alternatively Bayes’ law or Bayes’ rule), named after Reverend Thomas Bayes, describes the probability of an event, based on prior knowledge of conditions that might be related to the event.[1] For example, if the risk of developing health problems is known to increase with age, Bayes’ theorem allows the risk to an individual of a known age to be assessed more accurately (by conditioning it on their age) than simply assuming that the individual is typical of the population as a whole