Big-O-Smallest-to-Largest Flashcards

1
Q

1: Constant

A

O(1)

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

2: Logarithimic

A

O(log n)

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

3: Linear

A

O(n)

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

4: Linearithmic

A

O(n*log n)

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

5: Quadratic

A

O(n^2)

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

6: Cubic

A

O(n^3)

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

8: Exponential

A

O(2^n) or O(e^n), where e > 1

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

9: Factorial

A

O(n!)

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

O(n^4)

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

Array/List gets iterated over c * length times. Define Big O

A

O(n), where is n is the length of array or list

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

How will you identify O(log n)

A

When number of elements in the problem space gets halved each time.

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

How will you identify O(N^2)/Ouadratic

A

When we have a single nested loop

for (int i=0; i< n; i++{
for (int j=0; i

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

Find Big O for this

for (int i=0; i

A

O(nm)

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

Find Big O for this

for (int i=0; i

A

O(n^2)

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

Find Big O for this

for (int i=0; i

A

O(n)

Outer loop i is doubled and incremented each time.

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

Find Big O for this

i = //constant
n = //constant
k = //constant
while (i < n){
    i*=k;
    // Statement(s) that take(s) constant time
}
A

O(log to base K of n)
if K is 2, then O(log n)

Because the loop count is being doubled every time.

17
Q
Find Big O for this
p = 0
for (i = 0; p < n; i++) {
   p = p+i;
   // Statement(s) that take(s) constant time
}
A

O(sqrt(n))

For loop will run K time, as long as p < n

When ever we see, i getting incremented by its own value, then it will run sqrt of n time.

18
Q

Find Big O for this

for(i = 0; i < n; i++){
  i = i*2;
   // Statement(s) that take(s) constant time
}
And for this
for(i = 0; i < n; i++){
  i = i+2;
   // Statement(s) that take(s) constant time
}
A

First one: O(log n), as i is doubled every time.

Second one: O(sqrt n), as i is incremented by self every time.

19
Q

Complexity for

Accessing an element in an array

A

O(1)

20
Q

Complexity for

Traversing an array

A

O(N)

21
Q

Complexity for

Updating an element in an array

A

O(1)

22
Q

Complexity for

Inserting an element in the beginning

A

O(n)

23
Q

Complexity for

Appending an element in the end

A

Static Array: O(n)

Dynamic Array: Amortized O(1)

24
Q

Complexity for

Inserting an element in the middle

A

O(n)

25
Q

Complexity for

Removing an element from the middle

A

O(n)

As we have to shift

26
Q

Complexity for

Removing an element from the end

A

Static Array: O(n)

Dynamic Array: O(1) as we will update the tail index in Dynamic array

27
Q

Complexity for

Removing an element from the beginning

A

O(n)

28
Q

Copying an array

A

O(n)

29
Q

What does Big O try to answer?

A

It tells us about efficiency of algorithm in terms of time and space, as N - size of input - increases towards infinity.