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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:02:32+00:00 2026-06-05T09:02:32+00:00

I have a list of agents a = {a1, a2, a3,…, an} , in

  • 0

I have a list of agents a = {a1, a2, a3,..., an}, in which each agent may be paired up with zero or more other agents. For example, for n = 6, I can have:

a1: a2, a3, a5
a2: a1, a3, a4
a3: a1, a2. a5
a4: a2
a5: a1, a3
a6:

Each pair interact with each other, and each agent obtains a value as the result of this interaction (e.g. they can play a game, but the details of interaction can be abstracted away here). I am interested in computing and storing the results of these interactions based on a given pairwise structure such as above.

Obviously, a naive algorithm would be to go through each agent and then compute the pairwise interaction with each of his interacting partners one-by-one. However, it is also obvious that this approach will duplicate some (or potentially many) computation. Using the example above:

by the time we finish for agent a1, we would’ve already obtained the results for (a1, a2), (a1, a3), and (a1, a5), thus rendering the later computation among these pairs redundant when we do it for agent a2, a3, and a5,

An improved algorithm would be to sort the input structure in an ascending order in both dimensions (i.e. along agents themselves and along their respective partners) as in the example above, so that for each agent (e.g. a3), we only need to compute for the interactions between this agent (a3) and the ones that are ‘higher’ than him (a5), since we know the interactions between himself and ‘lower’ partners ((a1, a3), (a2, a3)) have already been computed.

I wonder if there is different and better algorithm for this problem? By better, I mean more efficient computation in terms of both time and space.

  • 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-05T09:02:34+00:00Added an answer on June 5, 2026 at 9:02 am

    Yes this tries to add each pair to the set twice, but I feel that this may be more efficient than the conditional. Does anyone want to try timing the alternatives?

    agents = {
        'a1': ['a2', 'a3', 'a5'],
        'a2': ['a1', 'a3', 'a4'],
        'a3': ['a1', 'a2', 'a5'],
        'a4': ['a2'],
        'a5': ['a1', 'a3'],
        'a6': []
    }
    pairs = {(k,v) for k in agents for v in agents[k]}
    

    This is still O(n), so in terms of efficiency beats anything involving sorting

    You’d probably get a minor speedup by using

    pairs = {(k,v) for k,vs in agents.iteritems() for v in vs}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data set which has a list of user agents and devices
I have an entity named Tour which can have many Agents . I am
I have List I want to sort Desc by Priority, which is int and
I have list of words. I type in a word misspelled. Can I query
I have list of files which contain particular patterns, but those files have been
Suppose you have the next class. It contains the systems in which the agent
I have 6 agent, 1 form(Agent Status), 1 view(Agent Status List), & 1 script
I have create a restful service which returning a List an entity type: [AspNetCompatibilityRequirements(RequirementsMode
I have build a script(by help of internet resources) which takes list of available
I have list of input area in the form with id like contact1_title, contact2_title,

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.