DSA - MATHS & COMPLEXITY Flashcards

1
Q

What is the time complexity for a loop?

A

O(n)

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

What is the time complexity for a nested loop?

A

O(n^2)

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

What is worst case for Linear search

A

O(n)

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

Why is Maths Good for Complexity Analysis?

A

Needs to check whether the choice ADTs is correct one for the chosen for the task or program

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

What Does 2^10 equal? & Why is it useful?

A

-1024
- Useful when calculating greater powers like 2^50

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

Define Log;

A

log_a(b) is the number you have to raise a to in order to get to b

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

What are the 2 Dimensions we might be interested in?

A

TIME & SPACE

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

What is TIME Performance?

A

How Long the algorithm takes to run?

Measure it in the number of Steps, due to normal time units depend on machine its on

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

What is SPACE Performance?

A

How much memory it requires?

Different algorithms to accomplish the same task may use different amounts of memory.

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

Define Big O:

A

f(n) = O(g(n))
=> g is an upper bound on how fast f grows as n increases
=> Only refer to relative growth.
How fast f grows in respect to how fast g grows

==> |f(n)| ≤ |Cg(n)|
where C is constant and n> n_0

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

Define little o:

A

f(n) = o(g(n))
=> A Stricter Upper Bound than BIG O

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

Define Theta:

A

f(n) = θ(g(n))
=> Provides both Upper bound and Lower bounds, which
are given as the same function but with different
constants

=> f & g grow at same rate
=> More precise than BIG O & little o
=> Tighter range of speeds for complexity
=> Bounded ABOVE but also BELOW x

==> C_1g(n) ≤ f(n) ≤ C_2g(n)
for positive constants of C_1, n_0& C_2, where n>n_0

=> f & g have the same rates of growth, with some constant
multiple
=> ONLY true if f(n) = O(g(n)) & g(n) = O(f(n))

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

Define Asymptotically Equal:

A

f(n) ~ g(n)
=> Stricter Upper and Lower Bounds
=> f’(n) = g’(n)
=> One grows faster the other would grow to 0 or ∞

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

Define Omega:

A

f(n)= Ω(g(n))
=> a Lower bound on how fast f grown as n increases
=> ONLY Lower bound of θ
=> Lower bound equivalent Big O
=> As f grows it will always grow at least at same rate as g
and CAN grow Faster

==> |f(n)|≥ |Cg(n)|
for a +ve C, n_0, where n>n_0

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

Average Case Complexity:

A

Average complexity overall all possible inputs

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

Define the Worst case time complexity?

A
  • Case that will take the largest number of steps
  • Max Time Taken => ideal for real-time situations to check if
    algorithm is suited
  • Worst case Tends to be Average case
  • Worst case analysis in real-time must be checked to see if it
    can still react quickly for highly critical scenarios.
17
Q

Define the Best Case Time Complexity?

A
  • Shortest Possible Time
  • Only when a Particular scenario or Case attempt
  • Ideal complexity for Algorithm
  • Companies want their algorithms to be better than everyone
    else
18
Q

Define the Average Case Time Complexity?

A
  • Consider case every possible case for an input of size n and
    calculate the Average
  • Tends to the complexity the algorithm will usually work at

ASSUME EACH CASE IS EQUALLY LIKELY

19
Q
A