notesonly.in

One notebook for every subject — open it anywhere.

Log in

Backtracking

Design and Analysis of Algorithms · Engineering

Study notes

4-queens: place Q at row 0 col 1; row 1 try col 3 (col 0,2 attacked); row 2: all columns attacked, dead end. Backtrack: move row-1 queen to next option, none work, backtrack to row 0 col 2... eventually [1,3,0,2] succeeds. Each dead end prunes a whole subtree.

← Back to topics for Engineering