Skip to content
RSS feed tkhwang on GitHub tkhwang on Twitter

πŸ”₯ How to solve algorithm problems and thought process

(🚧 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.

πŸ”₯ [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 or algorithm 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

  1. Understand the problem
  2. Make a plan
  3. Execute the plan
  4. 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 or something like it before ?
  • Abstraction
    • Once we recognize patterns, we can
      • remove the details.
      • form abstractions.
  • Algorithm design

πŸ“š References