Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3331554
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:35:45+00:00 2026-05-17T23:35:45+00:00

I’m trying to compute de Bruijn sequences for alphabets which have a number of

  • 0

I’m trying to compute de Bruijn sequences for alphabets which have a number of characters which is not a power of two.

For alphabets with a 2^k characters, calculating de Bruijn sequences is easy: There are several simple rules, such as “Prefer Ones” and “Prefer Opposites” which work for generating B(2,n). B(2^k,n) is exactly the same as B(2,kn), if you read the 1s and 0s as binary codes for the actual characters in your alphabet. E.g., you can interpret B(2,8n) as being over n-length sequences of bytes.

Prefer Ones is quite simple: Write n zeros. Then, always write a one unless it would cause the repetition of an n-length string; otherwise, write a zero.

Presently, I don’t see how to generalize such rules to non-power-of-two-sized alphabets.

There’s a general method for calculating de Bruijn sequences via graphs: Let each n-length sequence generated by your alphabet be a node; put an edge from A to B iff the rightmost n-1 characters of A are the same as the leftmost n-1 characters of B. Label each edge with the last character of the string in the head vertex. Any Eulerian path through this graph will generate a de Bruijn sequence, and the peculiar construction we used guarantees that there will be at least one such path. We can use Fleury’s Algorithm to (nondeterministically) construct an Eulerian path:

  1. Choose a vertex.
  2. Leave that vertex via some edge and delete that edge, only choosing edges whose deletion would disconnect the vertex from the graph if there is no alternative.
  3. Append to your string the label of the edge you just deleted.
  4. Goto 2 until all edges are gone.

The resulting string will be a de Bruijn sequence.

This algorithm is somewhat more complex to implement than Prefer Ones. The simplicity of Prefer Ones is that one needs only to consult the output already generated to determine what to do. Is there a straightforward way to generalize Prefer Ones (or, possibly Prefer Opposites) to alphabets of non-power-of-two sizes?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:35:46+00:00Added an answer on May 17, 2026 at 11:35 pm

    This is my C++ implementation of the algorithm in Figure 1 from a paper by Sawada and Ruskey:

    void debruijn(unsigned int t,
                  unsigned int p,
                  const unsigned int k,
                  const unsigned int n,
                  unsigned int* a,
                  boost::function<void (unsigned int*,unsigned int*)> callback)
    {
      if (t > n) {
        // we want only necklaces, not pre-necklaces or Lyndon words
        if (n % p == 0) {
          callback(a+1, a+p+1);
        }
      }
      else {
        a[t] = a[t-p];
    
        debruijn(t+1, p, k, n, a, callback);
    
        for (unsigned int j = a[t-p]+1; j < k; ++j) {
          a[t] = j;
          debruijn(t+1, t, k, n, a, callback);
        }
      }
    }
    
    struct seq_printer {
      const std::vector<char>& _alpha;
    
      seq_printer(const std::vector<char>& alpha) : _alpha(alpha) {}
    
      void operator() (unsigned int* a, unsigned int* a_end) const {
        for (unsigned int* i = a; i < a_end; ++i) {
          std::cout << _alpha[*i];
        }
      }
    };
    
    ...
    
    std::vector<char> alpha;
    alpha.push_back('a');
    alpha.push_back('b');
    alpha.push_back('c');
    
    unsigned int* a = new unsigned int[N+1];
    a[0] = 0;
    
    debruijn(1, 1, alpha.size(), N, a, seq_printer(alpha));
    if (N > 1) std::cout << alpha[0];
    std::cout << std::endl;
    
    delete[] a;
    

    The full reference for the paper is: Joe Sawada and Frank Ruskey, “An Efficient Algorithm for Generating Necklaces with Fixed Density”, SIAM Journal of Computing 29:671-684, 1999.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to loop through a bunch of documents I have to put
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.