Changes

Jump to: navigation, search

De Bruijn Sequence Generator

No change in size, 10:03, 23 May 2018
no edit summary
'''[[Main Page|Home]] * [[Programming]] * [[Algorithms]] * [[Backtracking]] * De Bruijn Sequence Generator'''
A [[Recursion|recursive]] backtracking implementation of a [[Bitboards|64-bit]] [[De Bruijn sequenceSequence]] generator in [[Cpp|C++]], to build a "private" [[BitScan#DeBruijnMultiplation|bitScanForward]]-routine. Compile the program, and start it with a parameter between 1 and 67108864 (2^26). Test-output with some "unique" private number. By [[Gerd Isenberg]].
=Program Output=
try {findDeBruijn(0, 64-6, 0, 6);} catch(int){}
stop = clock();
printf("\n%.3f Seconds for %d De Bruijn sequences Sequences found\n", (float)(stop - start) / CLOCKS_PER_SEC, m_dBCount);
}
void findDeBruijn(U64 seq, int depth, int vtx, int nz) {
if ( (m_Lock & pow2[vtx]) == 0 && nz <= 32 ) { // only if vertex is not locked
if ( depth == 0 ) { // depth zero, De Bruijn sequence Sequence found, see remarks
if ( ++m_dBCount == m_Match4nth )
bitScanRoutineFound(seq);
=Remarks=
With findDeBruijn(0, 64-6, 0, 6), starting with six leading zeros on its most significant top, the routine has 58 decrements to reach depth zero claiming a found De Bruijn sequenceSequence. The algorithm does not explicitly prove the uniqueness of six remaining indices which result from the up to five trailing hidden zeros with 100000B = 32 as least significant subsequence. However, the constraints of the odd De Bruin sequence seem strong enough to make that test redundant, that is proving 64-6 unique keys seems sufficient.
As demonstrated in the [[De Bruijn sequenceSequence#BruijnGraphChessBoard|De Bruijn Graph on a Chess Board]], there are two branch-less series {32, 0, 1} and {31, 63, 62} respectively. The recursive search routine performs some kind of pruning and reductions to take advantage of that. 63 to follow 31 must not be locked and skipped for the 62 with an extra depth reduction. 32 can not appear as index inside the 58 recursive tests in one path, and is therefor locked initially before the findDeBruijn(0, 64-6, 0, 6) call.
A small improvement was introducing an additional parameter for the number of binary zeros to check it not to become greater 32. This makes also the depth > 0 condition for the even successors no longer necessary, to enumerate all 2^26 De Bruijn sequencesSequences.
=Forum Posts=

Navigation menu