Asymptotic Analysis (Easy/Medium) Flashcards

1
Q

Two Number Sum

A

Time: O(n log(n))

Space: O(1)

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

Find Closest Value in BST

A

Time: O(log(n))

Space: O(1)

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

Depth First Search

A

Time: O(v + e)

Space: O(v)

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

Nth Fibonacci

A

Time: O(n)

Space: O(1)

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

Product Sum

A

Time: O(n)

Space: O(d)
Where d = greatest depth of the ‘special’ arrays

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

Binary Search

A

Time: O(log(n))

Space: O(1)

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

Find Three Largest Numbers

A

Time: O(n)

Space: O(1)

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

Bubble Sort

A

Time: O(n^2)

Space: O(1)

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

Insertion Sort

A

Time: O(n^2)

Space: O(1)

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

Palindrome Check

A

Time: O(n)

Space: O(1)

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

Caesar Cipher Encryptor

A

Time: O(n)

Space: O(n)

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

Branch Sums

A

Time: O(n)

Space: O(n)

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

Three Number Sum

A

Time: O(n^2)

Space: O(n)
Remember that the result is all ‘triplets’

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

Smallest Difference

A

Time: O(n log(n) + m log(m))

Space: O(1)

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

Move Element to End

A

Time: O(n)

Space: O(1)

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

Validate BST

A

Time: O(n)

Space: O(d) where d = depth

17
Q

Invert Binary Tree

A

Time: O(n)

Space: O(d) where d is depth of BST

18
Q

Max Subset Sum No Adjacent

A

Time: O(n)

Space: O(1)

19
Q

Group Anagrams

A

Time: O(wn log(n))

Space: O(wn)

20
Q

Levenshstein Distance

A

Time: O(mn)

Space: O(min(m,n))

21
Q

Kadane’s Algorithm

A

Time: O(n)

Space: O(1)

22
Q

Minimum number of coins for change

A

Time: O(nd) where n is target amount and d is number of denominations

Space: O(n)

23
Q

Remove Kth node from the end

A

Time: O(n)

Space: O(1)

24
Q

Permutations

A

Time: O(n * n!)

Space: O(n * n!)

25
Q

Balanced Brackets

A

Time: O(n)

Space: O(n)

26
Q

BST Traversal

A

Time: O(n)

Space: O(n)

27
Q

RiverSizes

A

Time: O(wh)

Space: O(wh)

where w = width and h = height of input matrix

28
Q

Youngest Common Ancestor

A

Time: O(d)

Space: O(1)

29
Q

ZigZag Traverse

A

Time: O(n)

Space: O(n)

30
Q

Suffix Trie

A

Creation:
Time: O(n^2)
Space: O(n^2)

Searching:
Time: O(m) where m is length of input string
Space: O(1)

31
Q

Search Sorted Matrix

A

Time: O(n + m) where n is #rows and m is #columns in matrix

Space: O(1)