Relative Content

Tag Archive for cbacktrackinggoto

Can Knuth’s “Algorithm B” be written without goto statements or recursion?

Though I’ve already implemented the basic recursive N queens solution, I’m trying to learn more about backtracking by studying and implementing Knuth’s “Algorithm B (Basic backtrack)” for the case of the N queens problem in C. If you want to read it, it’s here (https://cs.stanford.edu/~knuth/fasc5b.ps.gz). This is the code I have written so far, and it works well. It’s a straightforward translation of what he wrote into C using goto statements (with a few parts changed to account for zero-indexed arrays instead of one-indexed arrays).