Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 50s1 days 16 hours 1 minutes 50 seconds.
Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 50s1 days 16 hours 1 minutes 50 seconds.
Sign in to watch this lesson
Algorithms - Recursion, Backtracking and Combinatorics · 3:53
We solve the eight queens puzzle row by row, greying out every attacked square, and watch the search hit its first dead end (row six has no free square) and back up. Pulled back as a tree, checking each queen as it is placed visits 2,057 nodes against 19,173,961 for one queen per row checked only at the end, and both find the same 92 solutions. Then three bitmasks (columns and two diagonals that shift one place per row) make each check a couple of instructions: 14 queens, over 27 million nodes, ran in a fraction of a second on this Mac, several times faster than arrays; symmetry halves the work, and the most constrained choice goes first.