<aside> <img src="/icons/map-pin_gray.svg" alt="/icons/map-pin_gray.svg" width="40px" /> This is just a collection of equations, running time, probabilities, and etc. covered throughout the course.
</aside>
$N$-Queens problem:
Placing $N$ chess queens on an $N \times N$ chessboard so that no two share the same row, column, or diagonal.
1) Start in the leftmost column
2) If all queens are placed
return true
3) Try all rows in the current column. Do following for every tried row.
a) If the queen can be placed safely in this row then mark
this [row, column] as part of the solution and recursively
check if placing queen here leads to a solution.
b) If placing the queen in [row, column] leads to a solution
then return true.
c) If placing queen doesn't lead to a solution then unmark
this [row, column] (Backtrack) and go to step (a) to try
other rows.
4) If all rows have been tried and nothing worked,
return false to trigger backtracking.
Rat in a maze problem:
Finding a path from the starting position to the end position in a maze.
1) Create a solution matrix, initially filled with 0’s.
2) Create a recursive function, which takes initial matrix, output
matrix and position of rat (i, j).
3) If the position is out of the matrix or the position is not valid
then return.
4) Mark the position output[i][j] as 1 and check if the current
position is destination or not. If destination is reached print the
output matrix and return.
5) Recursively call for position (i+1, j) and (i, j+1).
6) Unmark position (i, j), i.e output[i][j] = 0.
$M$-coloring problem:
Assign colors to the vertices of a graph in a way that no two adjacent vertices have the same color.
1) Create a recursive function that takes the current index, number of
vertices and output color array.
2) If the current index is equal to number of vertices. Print the
color configuration in output array and break.
3) Assign a color to a vertex (1 to m).
4) For every assigned color, check if the configuration is safe,
recursively call the function with next index and number of
vertices.
5) If any recursive function returns true, break the loop and return true.
6) If no recursive function returns true, then return false.
Computing edit distance.
$$ D(i,j) = \textrm{min} \begin{cases} {\color{darkblue} D(i,j - 1) + 1} \\ {\color{green} D(i - 1,j) + 1} \\ {\color{purple} D(i - 1,j - 1) + 1} & \textrm{if } A[i] \neq B[i] \\ {\color{orange} D(i - 1,j - 1)} & \textrm{if } A[i] = B[i]\\ \end{cases} $$
Deriving the operations by backtracking from the answer.
