Input Constraints Flashcards

Time Complexity Requirements for LC Problems

1
Q

What time complexity/approach should you be thinking of for an input size of N = < 10 ?

A

Some logrithmic approach with higher than base 2; think backtracking/brute-force. Any algorithm that finds the correct answer is fine, this is non-restrictive.

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

What time complexity/approach should you be thinking of for an input size of 10 < N = < 20 ?

A

This is a non-restrictive condition, look for backtracking/recursion. Likely you are considering all possible subsets.

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

What time complexity/approach should you be thinking of for an input size of 20 < N = < 100 ?

A

Exponentials are too slow, cubic maybe.

Look for a brute force nested loop. Start with brute force and look for enhancements with hash maps or heaps.

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

What time complexity/approach should you be thinking of for an input size of 100 < N = < 1000 ?

A

Look for a nested loop solution, likely this is the optimal route.

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

What time complexity/approach should you be thinking of for an input size of 1,000 < N = < 100,000 ?

A

This is the most common constraint

Acceptable: O(n * log(n))
Goal: O(n)

Think about sorting or a heap. Any classic algorithm will be needed, sliding window, binary search, etc. Large constants are ok, eg looping over the Alphabet is O(26n)

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

What time complexity/approach should you be thinking of for an input size of 100,000 < N = < 1,000,000 ?

A

Will likely need O(n), maybe O(nlog(n)). Think of a hashmap.

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

What time complexity/approach should you be thinking of for an input size of 1,000,000 < N ?

A

Will need to be O(log(n)) or O(1). Use clever math or binary search or hashmaps.

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

What is the time complexity for the build in sorting method in Python?

A

O(nlog(n)), using Timsort

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