⚡ Build the skills to land top-paying quant jobs. Offer ends in 17d 22h 20m 22s17 days 22 hours 20 minutes 22 seconds.
⚡ Build the skills to land top-paying quant jobs. Offer ends in 17d 22h 20m 22s17 days 22 hours 20 minutes 22 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.