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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:38:18+00:00 2026-05-19T16:38:18+00:00

First a note: Sorry that my images aren’t separated. I’m a new member, so

  • 0

First a note: Sorry that my images aren’t separated. I’m a new member, so I don’t have enough reputation points to post more than a single hyperlink.

Let M be an n by n array (mathematically square matrix) of characters.

In M, I need to be able to find all permutation of characters with a restriction. The permutations do not have to be linear, but they they must contain characters such that each character is adjacent to at least one other character in the permutation. An example of an acceptable permutation follows below:

An unacceptable permutation is shown below.

I have derived this much:

  • A permutation can have at most n squared characters in it (as no characters can be repeated).
  • I do not know the exact number of permutation given the restrictions, but I believe there can be no more than the value generated by evaluating the expression pictured in the hyperlink.

I can very easily find the permutations which only contain characters in straight lines: vertical lines, horizontal lines, and diagonals. I am not sure of a way to exhaustively find all remaining permutations.

I have done research and have not been able to find a solution to a similar problem.

Any advice in the development of such an exhaustive algorithm would be greatly appreciated.

https://i.stack.imgur.com/uDNfv.png

  • 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-19T16:38:18+00:00Added an answer on May 19, 2026 at 4:38 pm

    One algorithm comes to mind immediately, though optimizations can be made, if time-complexity is a concern.

    At each element in the 2×2 array (or we can call it a matrix if you like), there are 8 directions that we can travel (North, NE, East, SE, South, SW, West, NW).

    The pseudo code for the meat of the algorithm goes a bit like this (I assume pass by value, so that “current_string” is a new string at each function call):

    find(position, direction, current_string){
        new_letter = m[0, position + direction];
        if(!current_string.Contains(new_letter)){
            // We have not yet encountered this letter during the search.
            // If letters occur more than once in the array, then you must
            // assign an index to each position in the array instead and
            // store which positions have been encountered along each
            // search path instead.
            current_string += new_letter;
            find(position, (0, 1), current_string);
            find(position, (1, 1), current_string);
            find(position, (1, 0), current_string);
            find(position, (1, -1), current_string);
            find(position, (0, -1), current_string);
            find(position, (-1, -1), current_string);
            find(position, (-1, 0), current_string);
            find(position, (-1, 1), current_string);
        } else {
            // This letter has been encountered during this path search,
            // terminate this path search. See comment above if letters
            // occur more than once in the matrix.
            print current_string; // Print one of the found strings!
        }
    }
    

    Now you need to add some checks for things like “is position + direction outside the bounds of the array, if so, print current_string and terminate”.

    The high level idea of the algorithm above is to search along all possible paths recursively, terminating paths when they run into themselves (in the same way that snakes die in the game Snake).

    If you use hashing to test containment of a new letter against the current string (as per the line if(!current_string.Contains(new_letter)){), which is amortized O(1) searching, then the worst case runtime complexity of this algorithm is linear in the number of possible strings there are in the matrix. I.e. if there are n possible string combonations in the matrix, then this algorithm takes about cn steps to complete for large n, where c is some constant.

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

Sidebar

Related Questions

Sorry for posting something that's probably obvious, but I don't have much database experience.
Its my first time here and I don't know how to indent this sorry
Note first of all that this question is not tagged winforms or wpf or
first of all, i am sorry that even if there's many given topic that
First as a note I am using this plugin in a Rails app. Ok
NOTE: I am not set on using VI, it is just the first thing
How can I retrieve the first and last record from a table. Note :
First off, I am using Windows XP. I have multiple hard drives and it
First of all, I know how to build a Java application. But I have
I'm trying to parse some text using PyParser. The problem is that I have

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.