algorithms analysis Flashcards

1
Q

what does correctness mean in algorithm analysis

A

an algorithm outputs the expected correct value

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

what is time efficiency

A

how fast and alorithm is excuted to get the result. the running time depends on the number of instructions to excute

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

what is space (memory) efficency

A

how much memory does the algorithm need during excution

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

what are the 3 things algorithm analysis look at

A
  • correctness
  • time efficency
  • space ( memory) efficency
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what are some things that affect run time

A
  • hardware
  • software
  • typically grows with the input size
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what are the analysis types

A
  • worst case
  • best case
  • average case
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

what are the limitations to runnign experiments for run time

A
  • it is nessary to implement the algorithm which could be hard
  • in order to compare two algorithms the same hardware and eviroments must be used
  • results may not be indicative of the running time on other inputs not included in the experiment
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

what is theoretical analysis

A
  • uses pseudocode instead of implementation
  • characterizes running time as a function of the input size n
  • take into account all possible inputs
  • allow us to evaluate the speed of an algorithm independent of teh hardware/software enviroment
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

how do you determinte the theoritical analysis of running time

A

determine the number of primitive operations ( basic operations) as a function of the input size

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

what is a primative operation

A
  • basic computatiions performed by algorithm
  • assume to take a constant execution time
  • largely independent from the programming language
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

what are some examples of primative operations

A

ex

  • assigning value to a variable
  • evaluating an arithmetic expression or boolean expression
  • accessing a single element of an array by index
  • calling a method
  • returning from a method
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

if wose case is (3n-1) and 2n is the best case what id the what is the worst case time of it

A

a(2n) <= T(n) <= (3n-1)

a- is fastest primative operation
b is slowest primative operation

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

does changing in hardware/ssoftware enviroment affect the growth rate of running time?

A
  • this affects T(n) by a constant factor

- does not alter the growth rate of T(n)

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

why does growth rate matter

A
  • can distinguish efficient vs inefficient algorthims
  • many large scale instances can be solved more easily
  • many real world problems have large sizes
  • small diffreneces on small input sizes
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

what does not affect growth rate?

A
  • constant factord

- lower order terms

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

What is asymptotic analysis

A

foucuses on the growth rate of the running time as a fucntion of the input size n
- how the running time increases with the input size in the limit as the input size increases without bound

notation

  • big oh
  • big omega
  • big theta
17
Q

What is some notation asymptotic analysis

A
  • big oh
  • big omega
  • big theta
18
Q

Big oh notation formula given f(n) and g(n)

A

we say f(n) is O(g(n) if there is a real positve constant c> 0 and interger constant n0 >= 1

so formula f(n) <= cg(n) for n>=n0

19
Q

big omega formula given f(n) and g(n)

A

we say f(n) is (g(n) if there is a real positve constant c> 0 and interger constant n0 >= 1

f(n) >= cg(n) for n>=n0

we say f(n) is O(g(n)) if both f(n) is O(g(n)) and f(n) is g(n)

20
Q

what does f(n) us O(g(n) do

A
  • f(n) is of order AT MOST g(n). f(n) is NOT faster then g(n) asymptotically
  • g(n) is an asymototic UPPER bound for f(n)
21
Q

f(n) is ( g(n))

A
  • f(n) is of order at LEAST g(n). f(n) is NOT slower then g(n) asymptotically
  • g(n) is an asymototic LOWER bound for f(n)
22
Q

f(n) is ( g(n))

A
  • f(n) is of order g(n). f(n)

- g(n) is an asymptotic TIGHT bound for f(n)

23
Q

what is transpose symmetry

A

f(n) is O)g(n)) iff g(n) is f(n)

24
Q

symmetry

A

f(n) is O(g(n)) iff g(n) is f(n)

25
Q

transitivity

A
  • f(n) is O)g(n)) and g(n) is O(h(n)) –> f(n) is O(h(n))
  • f(n) is Og(n)) and g(n) is (h(n)) –> f(n) is O (h(n))
    • f(n) is Og(n)) and g(n) is O(h(n)) –> f(n) is O(h(n))
26
Q

whats the diffrence between polynomial run time and exponenetial run time?

A
  • polynomial running time O(n^c) for some constant c>1
  • preferably the constant factors are not very large

expontential running time O(2^n) some constant b>1
- should almost never be seen as efficent

27
Q

what are the big Oh properties

A
  • drop the lower order term
  • drop the constant factors

ex
x + 3x^2 + 2x +9 would be O(n^2)

28
Q

what are the general rules for loops, nested loops, concecutive statements, and if elseif-else statements

A

loops
the running time of the statements instide the nested loop times the number of iterations

  • nested loops
    the running time of the statements insid ethe nested loops times the product of the sizes of all teh loops

-concecutive statements
add the running time

if - elseif -else statemenst
- the running time is the largest running times of the conditional blocks ( remember they are exclusive)

29
Q

how to get the runnning time of recursion calls

A

it depends on

  • how many recursive activations occur
  • for each invocation of the mehtod we only account for the number of operations that are performed within the body of activation
  • take the sum over all activations