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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:35:41+00:00 2026-05-20T19:35:41+00:00

To make it more specific, I need an algorithm (recursive or not) that, given

  • 0

To make it more specific, I need an algorithm (recursive or not) that, given a integer n and a matrix as input, will return me all of the combinations that will have:
1) At least 1 object from each line
2) Will have n objects total

I feel I could solve this easier if I just tried all combinations and use the ones that have n objects and 1 from each line, but I believe that the algorithm can be a lot more efficient than that.
I have also successfully coded an algorithm that will return all combinations of 1 object per line, but couldn’t expand it to more. I’ve been coding in Python, but any language is fine. Extra points for consideration that python passes objects per reference. =)

Assume the matrix is squared. If anyone wants to know why, this is part of a more complex graph algorithm I’m trying to solve.

Thanks all!

  • 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-20T19:35:42+00:00Added an answer on May 20, 2026 at 7:35 pm

    Thanks for all the answers, they were close to what I was looking for. I managed to do it under Python (so I didn’t check the results posted here), my problem was actually Python passing reference vs copy in function calls. I thought a shallow copy would have been enough, but apparently I needed a deep copy (haven’t thought it through why shallow wasn’t enough).

    This is how I did it:
    PS1: Graphs here are dictionaries of lists. n_edges is the number of edges to be picked from the graph
    PS2: Size calculation here is pretty inefficient, haven’t taken time to fix it yet.
    PS3: In order to iterate orderly over a dictionary, I created two lists: a list-of-lists representation of the graph (lol) and an index array that matches it (lolindex).
    PS4: Adapted to fit the question I posted, the real method I used has more problem specific code to it. Haven’t tested the code in the way I put it here.

    def pickEdges(n_edges, newgraph):
        size = sum(len(v) for v in newgraph.itervalues())
        if (size == n_edges):
            print newgraph
            return
    
        for i in range(len(lol)):
            for j in range(len(lol[i])):
                    tmpgraph = copy.deepcopy(newgraph)
                    if (lol[i][j] not in tmpgraph[lolindex[i]]):
                           tmpgraph[lolindex[i]].append(lol[i][j])
                           pickEdges(n_edges, tmpgraph)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I will be more specific with a question if I need to be, or
I am editing the question to make it more specific. I want to run
I am trying to get a list together of tools/libraries that make me more
[ Update: Changed question title to be more specific] Sorry if I didn't make
To be more specific, I have an app that has multiple tableViews that drill
I edited the question so it would make more sense. I have a function
I have the following tables. I wanted it so when I make more boxes
I am really trying to be a better programmer, and to make more modular,
To make this more clear, I'm going to put code samples: $file = fopen('filename.ext',
How to make one more eval merge ? <asp:HiddenField ID=HiddenField1 runat=server Value='<%# Eval(Name),Eval(Surname),Eval(Mail)%>'/>

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.