Computational Complexity Flashcards

1
Q

What is computational complexity

A

determines if an algorithm is feasible for a certain problem, as data size increases and allows comparison between two algorithms being used for the same problem

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

time efficiency

A

how run time changes as the problem’s parameters and input increases in size

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

what does n represent

A

the problem size (length of list/array)

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

what does T(n) represent

A

amount of time it takes to execute problem size n
the equation represents if the algorithm is constant, linear, quadratic, exponential
this tells how time is proportional to the size of the list

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

how do you get the equation for T(n)

A

by counting the # of operations an algorithm will need for problem size N
cannot get the exact formula, just general characteristics

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

what is Big-O notation

A

mathematical notation for talking about general categories of notations
the characteristics of Big-O notation tell us whether the formula is quadratic, linear etc
O(1), O(n) etc

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

How to get Big-O formula

A

from T(n), get the most dominate term and drop coefficient

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

General rules

A

Rule 1 - straight-line code
Rule 2 - consecutive sections of code
Rule 3 - if statements
Rule 4 - simple loops

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

Rule 1 - straight line code

A
  • straight-line code has no function calls, not dependent on the size of the input
  • constant-time operations O(1)
    EX. variable assignment, arithmetic, array access
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Rule 2 - consecutive sections of code

A
  • where 1 bit of code runs, followed by a loop or another piece of code
  • to get Big-O, find max O(n) of O(f(n) and O(g(n))
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Rule 3 - if statements

A
  • find max of if and else statement
    EX. max(f(n) and g(n))
    nested loops require finding the complexity of inner loop * outer loop
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

rule 4 - simple loops

A

The complexity of the loop body TIMES the number of iterations
EX. 2n*O(n^2) = O(n^3)
** repeating a constant number of times in a loop doesn’t change complexity **
** nested loops require the complexity of inner loop * complexity of outer loop **

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

O(log n)

A
  • decreasing iterations through the array consistently
    EX. n = n/2
    most efficient
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Attributes of algorithms

A
  • solves computational problem
  • ease of understanding
  • efficiency
  • elegance
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Comparing algorithms

A
  • comparing attributes

- comparing time complexity best/worst/avg cases

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

Best, worst, average complexity

A

Best - smallest amount (T(n) = 1)
Worst - greatest amount of work (T(n) = n)
Avg - likelihood of different scenarios occurring (T(n) = n/2)

17
Q

O(1)

A

constant time

- arithmetic, variable assignments, accessing an array

18
Q

O(n)

A

linear time

- proportional to the size of the list/array

19
Q

O(n^2)

A

quadratic

- nested loops, dependent on the size of the list/array

20
Q

O(log n)

A
  • dividing the proportion of the array accessed each time
  • efficient
  • the base is what n size is divided by
    EX. O(log 2 n) O(log 3 n)
21
Q

O(2^n)

A
  • grows fastest

- polynomial