Data structures and Algorithms Flashcards

1
Q

What is time complexity analyzed for?

A

1) Very large input size

2) Worst case scenario

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

What is the time complexity of T(n) = 2n^2+3n+1?

A

1) Drop lower order terms
2) Drop constants

Time complexity is O(N) = n^2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
How do you calculate the time complexity of a single loop?
for (int i = 1; i <= n; i++)
{
 x = y + z;
}
A
for (int i = 1; i <= n; i++)
{
 x = y + z; //constant time - C
}
Time complexity is C*N. Since you traverse N number of elements.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you calculate the time complexity of a nested loop?

A

1) Figure out how many times each loop will pass

2) Multiply each loop

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

How do you calculate time complexity of sequential statements?

A

You add the time complexities of each statement.

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

How do you calculate time complexity of if else statements?

A

You take the worse complexity of the two conditions.

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

What is the order of time complexities

O(logN), O(NlogN), O(n!), O(1), O(n), O(c^n), O(n^c). From worst to best.

A

O(n!) > O(c^n) > O(n^c) > O(NLogN) > O(n) > O(logN) > O(1)

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

What is the time complexity of selection sort?

A

Best: n^2
Average: n^2
Worst: n^2

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

What is the time complexity of bubble sort?

A

Best: `n
Avergage: n^2
Worst: n^2

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

What is the time complexity of insertion sort?

A

Best: n
Average: n^2
Worst: n^2

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

What is the time complexity of heap sort?

A

All: NLogN

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

What is the time complexity of quick sort?

A

Best, Average: NlogN

Worst: N^2

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

What is the time complexities of merge sort?

A

All: NlogN

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

What is the time complexities of bucket sort?

A

Best, Average: N+K

Worst: N^2

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

What is the time complexities of radix sort?

A

Best, Average, Worst: N*K

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

What is the space time trade-off?

A

The more time efficiency you have, the less space efficiency you have and vice versa.