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

  • Home
  • SEARCH
  • 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 9140263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:29:36+00:00 2026-06-17T09:29:36+00:00

I have a 4×4 2D array of characters like this: A B C D

  • 0

I have a 4×4 2D array of characters like this:

A B C D
U A L E
T S U G
N E Y I

Now, I would need to find all the permutations of 3 characters, 4 characters, etc till 10.

So, some words that one could “find” out of this are TEN, BALD, BLUE, GUYS.

I did search SO for this and Googled, but to no concrete help. Can you push me in the right direction in which algorithm I should learn (A* maybe?). Please be gentle as I’m no algorithms guy (aren’t we all (well, at least a majority :)), but am willing to learn just don’t know where exactly to start.

  • 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-17T09:29:37+00:00Added an answer on June 17, 2026 at 9:29 am

    Ahhh, that’s the game Boggle isn’t it… You don’t want permutations, you want a graph and you want to find words in the graph.

    Well, I would start by arranging the characters as graph nodes, and join them to their immediate and diagonal neighbours.

    Now you just want to search the graph. For each of the 16 starting nodes, you’re going to do a recursion. As you move to a new node, you must flag it as being used so that you can’t move to it again. When you leave a node (having completely searched it) you unflag it.

    I hope you see where this is going…

    For each node, you will visit each of its neighbours and add that character to a string. If you have built your dictionary with this search in mind, you will immediately be able to see whether the characters you have so far are the beginning of a word. This narrows the search nicely.

    The kind of dictionary I’m talking about is where you have a tree whose nodes have one child for each letter of the alphabet. The beauty of these is that you only need to store which tree node you’re currently up to in the search. If you decide you’ve found a word, you just backtrack via the parent nodes to work out which word it is.

    Using this tree style along with a depth-first graph search, you can search ALL possible word lengths at the same time. That’s about the most efficient way I can think of.


    Let me just write a pseudocodish function for your graph search:

    function FindWords( graphNode, dictNode, wordsList )
        # can't use a letter twice
        if graphNode.used then return
    
        # don't continue if the letter not part of any word
        if not dictNode.hasChild(graphNode.letter) then return
        nextDictNode = dictNode.getChild(graphNode.letter)
    
        # if this dictionary node is flagged as a word, add it to our list
        nextDictNode.isWord()
            wordsList.addWord( nextDictNode .getWord() )
        end
    
        # Now do a recursion on all our neighbours
        graphNode.used = true
        foreach nextGraphNode in graphNode.neighbours do
            FindWords( nextGraphNode, nextDictNode, wordsList )
        end
        graphNode.used = false
    end
    

    And of course, to kick the whole thing off:

    foreach graphNode in graph do
        FindWords( graphNode, dictionary, wordsList )
    end
    

    All that remains is to build the graph and the dictionary. And I just remembered what that dictionary data structure is called! It’s a Trie. If you need more space-efficient storage, you can compress into a Radix Tree or similar, but by far the easiest (and fastest) is to just use a straight Trie.

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

Sidebar

Related Questions

I have Json String array ,which looks like this , { {name:214,value:true,Id:0}, {name:215,value:true,Id:0}, {name:216,value:true,Id:0}
I have a php array like this: [ ['url_id' => 2191238, 'time_spent' => 41],
I have an array and I need to truncate this array down to only
I have a bit multidimensional array like this one: [[2, 1], [751, 159], [793,
I have an array in php like this : Array ( [0] => Array
Have dict like: mydict= {'a':[],'b':[],'c':[],'d':[]} list like: log = [['a',917],['b', 312],['c',303],['d',212],['a',215],['b',212].['c',213],['d',202]] How do i
Say you have an array like dat <- array(c(126, 100, 35, 61, 908, 688,
I have a shooping cart and I would like to save the $_SESSION['cart'] which
Below is the code that I now have. This gives me a 2 dimensional
I have a text file that looks like this: STUFF UP HERE APEXED NUMBER

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.