Time & Space Complexity Flashcards

1
Q

Horrible to Excellent Complexity

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

Binary Search in a sorted array of N elements

A

O(log N)

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

Reversing a string of N elements

A

O(N)

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

Linear search in an unsorted array of N elements

A

O(N)

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

Compare two strings with lengths L1 and L2

A

O(min(L1,L2))

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

Computing the Nth Fibonacci number using dynamic programming

A

O(N)

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

Checking if a string of N characters is a palindrome

A

O(N)

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

Finding a string in another string using the Aho-Corasick algorithm

A

O(N)

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

Sorting an array of N elements using Merge Sort/Quick Sort/Heap Sort

A

O(N ∗ log N)

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

Sorting an array of N elements using Bubble sort

A

O(N^2)

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

Two nested loops from 1 to N

A

O(N^2)

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

The Knapsack problem of N elements with capacity M

A

O(N*M)

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

Finding a string in another string – the naive approach

A

O(L1*L2)

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

Three nested loops from 1 to N

A

O(N^3)

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

Twenty-eight nested loops … you get the idea

A

O(N^28)

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

Generating all subsets of a set of N elements

A

O(2^N)

16
Q

Adding a value to the top of a stack

A

O(1)

17
Q

Removing the value at the front of the queue

A

O(1)

17
Q

Adding a value to a hash

A

O(1)

18
Q

Checking if a value is in a hash

A

O(1)

18
Q

Removing the value at the top of a stack

A

O(1)

19
Q

Adding a value to end of the queue

A

O(1)

20
Q

Reversing a stack

A

O(N)

21
Q

Reversing a queue

A

O(N)

22
Q

Adding a value to the heap

A

O(logN)

23
Q

Removing the value at the top of the heap

A

O(logN)