(π§ This page is under construction.)
As I have learned and practiced solving algorithm and data-structure problems, I'm looking for general guidelines
to show the general thought process to find how to solve the algorithms and data-structure problems.
π Consider the algorithm according to the input size
~ 20
:O(2^n)
~1000
:O(n^2)
nested for loop
can be used.
~10^5
:O(n logn)
- Hash map
- A two pointers implementation like sliding window
- Monotonic stack
- Binary search
- Heap
- A combination of any of the above
~10^9
:O(logn)
π₯ [object Object] or [object Object] related problems
It should be continuous.
- sliding window algorithm
- prefixSum style problem solving : prefix + something
π₯ [object Object] related problem
It can be dis-continuous.
π₯ Problem describes what to do exactly, but large data
- Usually, it won't work just do what you are told.
- You should FIND
pattern
oralgorithm
to calculate it in more faster way.
ποΈ Typical problems
Starting from left to right, remove the first number and every other number afterward until you reach the end of the list.
Repeat the previous step again, but this time from right to left, remove the rightmost number and every other number from the remaining numbers.
Keep repeating the steps again, alternating left to right and right to left, until a single number remains.
β¨ From [object Object]
π‘ How to solve it
- Understand the problem
- Make a plan
- Execute the plan
- Evaluate the result
π‘ How to solve it with [object Object]
- Decomposition
- the opposite of composition
- breaking a problem down into smaller parts
- Pattern recognition
- Where have I seen
this
orsomething like it
before ?
- Where have I seen
- Abstraction
- Once we recognize patterns, we can
- remove the details.
- form abstractions.
- Once we recognize patterns, we can
- Algorithm design