Introduction to Backtracking
Have you ever run into these problems in your daily life?
- For my luggage lock, what are some of the interesting password combination I can come up with? ๐
- For my living room, how many possible ways I can rearrange my sofa, table, speakers and TV? ๐บ
- Or, yes! this is a good one, given a set of liquors and juice, what are possible cocktails I can come up with? ๐น
#
Backtracking"Backtracking can be defined as a general algorithmic technique that considers searching every possible combination in order to solve a computational problem."
#
Intuitions of A Backtracking Problem- The problem is about combinations, combinatorics, and permutation. Usually the problem has multiple possible solutions and it asks you to "list" or "enumerate" all the possible solutions.
- When you try to come up with an combination of both iteration and recursion. For example, you need to have a loop inside of a recursive function, and the loop's range depends on the function parameters:
- When you can prove that the solution needs a runtime of