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 8321529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:03:07+00:00 2026-06-08T23:03:07+00:00

I am wondering about algorithm generating sequence of binary strings of length n with

  • 0

I am wondering about algorithm generating sequence of binary strings of length n with k ones where next string differs in two digits.

For example:

11100
11010
11001
10101
10110
10011
00111
01011
01101
01110
11100

Of course, there must be used all n \choose k binary strings.

  • 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-06-08T23:03:09+00:00Added an answer on June 8, 2026 at 11:03 pm

    You should read my blog post on this kind of permutation (amongst other things) to get more background – and follow some of the links there.

    Here is a version of my Lexicographic permutations generator fashioned after the generation sequence of Steinhaus–Johnson–Trotter permutation generators that does as requested:

    def l_perm3(items):
        'Generator yielding Lexicographic permutations of a list of items'
        if not items:
            yield [[]]
        else:
            dir = 1
            new_items = []
            this = [items.pop()]
            for item in l_perm(items):
                lenitem = len(item)
                try:
                    # Never insert 'this' above any other 'this' in the item 
                    maxinsert = item.index(this[0])
                except ValueError:
                    maxinsert = lenitem
                if dir == 1:
                    # step down
                    for new_item in [item[:i] + this + item[i:] 
                                     for i in range(lenitem, -1, -1)
                                     if i <= maxinsert]:
                        yield new_item                    
                else:    
                    # step up
                    for new_item in [item[:i] + this + item[i:] 
                                     for i in range(lenitem + 1)
                                     if i <= maxinsert]:
                        yield new_item                    
                dir *= -1
    
    from math import factorial
    def l_perm_length(items):
        '''\
        Returns the len of sequence of lexicographic perms of items. 
        Each item of items must itself be hashable'''
        counts = [items.count(item) for item in set(items)]
        ans = factorial(len(items))
        for c in counts:
            ans /= factorial(c)
        return ans
    
    if __name__ == '__main__':
        n = [1, 1, 1, 0, 0]
        print '\nLexicograpic Permutations of %i items: %r' % (len(n), n)
        for i, x in enumerate(l_perm3(n[:])):
            print('%3i %r' % (i, x))
        assert i+1 == l_perm_length(n), 'Generated number of permutations is wrong'  
    

    The output from the above program is the following for example:

    Lexicograpic Permutations of 5 items: [1, 1, 1, 0, 0]
      0 [1, 1, 1, 0, 0]
      1 [1, 1, 0, 1, 0]
      2 [1, 0, 1, 1, 0]
      3 [0, 1, 1, 1, 0]
      4 [0, 1, 1, 0, 1]
      5 [1, 0, 1, 0, 1]
      6 [1, 1, 0, 0, 1]
      7 [1, 0, 0, 1, 1]
      8 [0, 1, 0, 1, 1]
      9 [0, 0, 1, 1, 1]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just wondering about the performance impact of copying very large php variables. For example
I have been wondering about how people manage their strings if they are likely
I'm wondering about an algorithm solving the following (efficiently): A 2D matrix of numbers
I was wondering about a strange idea: you are given and algorithm wich takes
Recently, someone asked about an algorithm for reversing a string in place in C
I was wondering about some other valid alternative to the XOR Bit-Level encryption algorithm.
I've been wondering about the effiency of OOP connections. The example structure is shown
Just wondering about this code below... when I turn off my internet connection and
Just wondering about some practice about this; I have made a simple visual C#
I was wondering about how to add the autocomplete JQuery UI widget to a

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.