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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:15:33+00:00 2026-06-03T11:15:33+00:00

I am looking for an algorithm which, given a set of numbers {0, 1,

  • 0

I am looking for an algorithm which, given a set of numbers {0, 1, 2, 4, 5…} and a set of conditions on the relative positions of each element, would check if a valid permutation exists. The conditions are always of type “Element in position i in the original array must be next(adjacent) to element in position j or z”.
The last and first element in a permutation are considered adjacent.

Here’s a simple example:

Let the numbers be {0, 1, 2, 3}
and a set of conditions: a0 must be next to a1, a0 must be next to a2, a3 must be next to a1
A valid solution to this example would be {0,1,3,2}.

Notice that any rotation/symmetry of this solution is also a valid solution. I just need to prove that such a solution exists.

Another example using the same set:
a0 must be next to a1, a0 must be next to a3, a0 must be next to a2.

There is no valid solution for this example since a number can only adjacent to 2 numbers.

The only idea I can come up with right now would be to use some kind of backtracking.
If a solution exists, this should converge quiet fast. If no solution exists, I can’t imagine any way to avoid checking all possible permutations.
As I already stated, a rotation or symmetry doesn’t affect the result for a given permutation, therefor it should be possible to reduce the number of possibilities.

  • 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-03T11:15:35+00:00Added an answer on June 3, 2026 at 11:15 am

    Formulate this as a graph problem. Connect every pair of numbers that need to be next to each other. You are going to end up with a bunch of connected component. Each component has a number of permutations (lets call them mini-permutations), and you can have a permutation of the components.

    When you create the graph make sure each component follows a bunch of rules: no cycles, no vertices with more than two vertices etc.

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

Sidebar

Related Questions

I am looking for an algorithm as follows: Given a set of possibly overlapping
I'm looking for an algorithm which given a messy value (like a url with
I am looking for a simple but efficient Objective-C algorithm which, starting from a
I am looking for a command line either for an algorithm (script) which allows
I'm looking for a javascript diff algorithm implementation or library, which has been tested
I'm looking for an algorithm that given two permutations of a sequence (e.g. [2,
I'm looking for a packing algorithm which will reduce a regular polygon into rectangles
I am looking for an algorithm to encrypt secret numbers on a mobile device
Given a DAG, in which each node belongs to a category, how can this
Let's say I have a large set of data within which each datum has

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.