Code Monkey home page Code Monkey logo

duval-debruijn's Introduction

Duval's Algorithm for Binary de Bruijn Sequences

This program implements Duval's algorithm to generate binary de Bruijn sequences. The algorithm always returns the lexicographically smallest (first in the alphabet) sequence of a given order. We print the result to stdout in human-readable form, using one byte per digit.

A major advantage of Duval's algorithm is that it runs in amortized O(1) time per bit and requires only O(n) memory. For almost all use cases, n will be less than 40, so the memory usage is negligible. This implementation also runs about 20-40% faster than my prefer-one implementation for medium-sized inputs (20 <= n <= 24).

Compiling

To compile, just run make. To clean up the directory, use make clean.

Usage

To generate the order-n sequence, run ./duval n (Linux) or duval.exe n (Windows). The value of n can be any positive int.

For example, to generate the order-8 sequence and pipe the result to output.txt, run ./duval 8 > output.txt (Linux) or duval.exe 8 > output.txt (Windows).

Examples

Shown below are the order-n sequences generated by the program, for n <= 6:

n=1: 01

n=2: 0011

n=3: 00010111

n=4: 0000100110101111

n=5: 00000100011001010011101011011111

n=6: 0000001000011000101000111001001011001101001111010101110110111111

References

  • A description (in French) of the algorithm can be found in the original paper by Jean-Pierre Duval, "Génération d'une section des classes de conjugaison et arbre des mots de Lyndon de longueur bornée."

duval-debruijn's People

Contributors

man4 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.