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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:05:15+00:00 2026-05-11T02:05:15+00:00

I have a list of objects (for the sake of example, let’s say 5).

  • 0

I have a list of objects (for the sake of example, let’s say 5). I want a list of some of the possible permutations. Specifically, given that some pairs are not together, and some triples don’t make sandwiches, how can I generate all other permutations? I realize that I generate all of them first and check that they work, but I think it would be faster to not even consider the pairs and triples that don’t work.

Am I wrong that it would be faster to check first and generate later?

How would I do it?

  • 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. 2026-05-11T02:05:16+00:00Added an answer on May 11, 2026 at 2:05 am

    You would have to find an algorithm that cuts off more than one unwanted permutation after a single check, in order to gain anything. The obvious strategy is to build the permutations sequentially, for example, in a tree. Each cut then eliminates a whole branch.

    edit:
    Example: in the set (A B C D), let’s say that B and C, and A and D are not allowed to be neighbours.

            (A)                (B)                (C)                (D)      /  |  \            /  |  \            /  |  \            /  |  \  AB     AC    AD     BA    BC   BD      CA    CB   CD      DA    DB   DC  |  \   |  \   X    / \    X    / \     / \   X    / \     X    / \    / \ ABC ABD ACB ACD   BAC BAD     BDA BDC  CAB CAD   CDA CDB     DBA DBC DCA DCB  X   |   X   |     |   X       X   |    |   X     X   |       |   X   |   X     ABDC   ACDB  BACD            BDCA  CABD         CDBA     DBAC    DCAB      v       v     v               v     v            v        v       v 

    Each of the strings without parentheses needs a check. As you see, the Xs (where subtrees have been cut off) save checks, one if they are in the third row, but four if they are in the second row. We saved 24 of 60 checks here and got down to 36. However, there are only 24 permutations overall anyway, so if checking the restrictions (as opposed to building the lists) is the bottleneck, we would have been better off to just construct all the permutations and check them at the end… IF the checks couldn’t be optimized when we go this way.

    Now, as you see, the checks only need to be performed on the new part of each list. This makes the checks much leaner; actually, we divide the check that would be needed for a full permutation into small chunks. In the above example, we only have to look whether the added letter is allowed to stand besides the last one, not all the letters before.

    However, also if we first construct, then filter, the checks could be cut short as soon as a no-no is encountered. So, on checking, there is no real gain compared to the first-build-then-filter algorithm; there is rather the danger of further overhead through more function calls.

    What we do save is the time to build the lists, and the peak memory consumption. Building a list is generally rather fast, but peak memory consumption might be a consideration if the number of object gets larger. For the first-build-then-filter, both grow linearly with the number of objects. For the tree version, it grows slower, depending on the constraints. From a certain number of objects and rules on, there is also actual check saving.

    In general, I think that you would need to try it out and time the two algorithms. If you really have only 5 objects, stick to the simple (filter rules (build-permutations set)). If your number of objects gets large, the tree algorithm will at some point perform noticably better (you know, big O).

    Um. Sorry, I got into lecture mode; bear with me.

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

Sidebar

Ask A Question

Stats

  • Questions 77k
  • Answers 77k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer I don't see why it would cause a leak, but… May 11, 2026 at 3:26 pm
  • added an answer You could try something like Process Monitor, to watch what… May 11, 2026 at 3:26 pm
  • added an answer One of the nice things about R is that you… May 11, 2026 at 3:26 pm

Related Questions

I have a list of objects (for the sake of example, let's say 5).
I have a List<> of objects in C# and I need a way to
I have a generic list of objects in C#, for example sake, here's what
Is it possible to do a cast within a LINQ query (for the compiler's
I asked a similar question yesterday that was specific to a technology, but now

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.