Runtime Complexity Flashcards

1
Q

Describe “N” or Linear runtime.

A

It is when there is a direct correlation between the amount of inputs into the algorithm and the amount of work needed to be done.
Example: a function taking a string as an arg and processes each element

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

Describe “N^2” or Quadratic runtime.

A

It is when n increases and much more work is done per n.

Example is when there is a nested for loop

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

Describe “log(n)” or Logarithmic runtime.

A

This is when doubling the number of elements to iterate over does not double the amount of work. Always assume searching algorithms are log(n)

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

In Big O Notation, what is O(n)?

A

Linear Runtime

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

In Big O Notation, what is O(1)?

A

Constant Runtime

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

In Big O Notation, what is O(n^2)?

A

Quadratic Runtime

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

What is the runtime of your algorithm if you are iterating over a single collection?

A

Linear or O(n)

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

What is the runtime of your algorithm if you are iterating over 2 different collections in 2 separate for loops?

A

O(n +m)

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

What is the runtime of your algorithm if you have nested for loops iterating over the same collection?

A

Quadratic or O(n^2)

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

What is the runtime of your algorithm if you have nested for loops iterating over different collections?

A

O(n * m)

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

What is the runtime of a sorting algorithm?

A

O(n*log(n))

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

What is the runtime of a searching algorithm?

A

O(log(n))

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

What is space complexity?

A

The amount of memory used to complete a task

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

What is the time complexity of the Fibonacci iterative solution?

A

Linear if using memoization, otherwise its exponential

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

What is the time complexity of the Fibonacci recursive solution?

A

Exponential

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

How do you optimize the Fibonacci algorithm?

A

Use memoization:

  • Code the existing fib function
  • Code a memoization function that take the fib func as argument
  • If the args have been called before, return cache version
  • If not, call the fn using apply with the args
17
Q

What is the time complexity of BFS and DFS?

18
Q

What is the time complexity of sliding window?