Backtracking

Backtracking
Backtracking is a technique of solving a problem by going down a path to look for a solution, and either returning the solution if one is found, or abandoning that path to try a different one. Typically backtracking is done by having a function call itself.
A classic backtracking problem is the eight queens puzzle. Systematically put the queens on different squares, and if the placement allows two queens to attack, abandon that placement and try a different one.
Project 1: Jump Game
Template: Click this link, fork, and add your username to the project name: new project
Hint: Start at the first square, and jump to different squares. From each of those squares, jump again. Continue the process until the last square is reached, or until all jump sequences have been exhausted.
Hint: Make a jump function, and have that function call itself to jump again. Pass the current jump sequence as a parameter in order to highlight the solution later. When passing the jump sequence as a parameter, make a copy of it first with the slice method.
Project 2: Word Search
Template: Click this link, fork, and add your username to the project name: new project
Project 3: Sudoku Generator
Template: Click this link, fork, and add your username to the project name: new project
Note: The visualize button is to help you see how backtracking works. You do NOT need to make that button for your project.
Project 4: Expression Parser
Template: Click this link, fork, and add your username to the project name: new project
Note: The visualize button is to help you see how backtracking works. You do NOT need to make that button for your project.
Hint: Extract the terms and operators with a loop. A term can be a number or a subexpression in parentheses.
Hint: Evaluate each term. If the term is a number, the evaluation is simple. If the term is a subexpression, evaluate it recursively. Determine if a term is a number with the isNaN function.
Project 5: Minesweeper
Template: Click this link, fork, and add your username to the project name: new project
Hint: When revealing the number of neighboring mines, if the number is zero, recursively reveal the number of neighboring mines for all neighboring squares. This is an example of the flood fill algorithm.
Hint: For detecting a right click, refer to the right click page.
Last section Next section