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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:52:21+00:00 2026-05-31T13:52:21+00:00

I have this Problem and solving it is not the problem, more like what

  • 0

I have this Problem and solving it is not the problem, more like what is the fastest way doing it.
So i am asking the more experienced of you to help me find a fast solution.

I have People, each defined as a Integer between 1000 and 3000.
Every of these people can be assigned to someone else, this would look like:
<Integer for p1, Integer for p2>
There are some rules for these connections, there will be not more than 10000, but at least one of them
and each pair of people can only occur once, so <1000,2000> and <2000,1000> are not allowed!
At the Moment i store all of these connections in a LinkedList where Connection is a Class containing the two Integers of the two people.

I then need to find the person occuring the most times in all connections, if there are more than one, i would need to have all of them unsorted.

After that, i will iterate through the LinkedList and delete all connections where these people participated and redo the process until the list is empty.

Some problems i encountered are Concurred Access or use of the wrong Maps/Lists and a slow method of sorting.

I have no code at the moment, since i saw the performance of my old one and started from scratch with now nothing other than processing the input (witch is already optimized) 😉

What would help me most is someone looking at my case and telling me his experiences of how fast different solutions with different Datatypes are. I want to write the code mostly myself, i just need some hints how to do it right.

Thanks for the attention and hopefully for an answer.
If something is unclear, i appologise for that and will clarify it upon asking 🙂

  • 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-31T13:52:22+00:00Added an answer on May 31, 2026 at 1:52 pm

    If we look at this the object oriented way, we can have each Person store a List of their friends:

    class Person {
        private Set<Person> friends = new HashSet<>();
    
        public void addFriend(Person newFriend) {
            friends.add(newFriend);
            newFriend.friends.add(this);
        }
    
        public void removeFriend(Person oldFriend) {
            friends.remove(oldFriend);
            oldFriend.friends.remove(this);
        }
    
        public int numberOfFriends() {
            return friends.size();
        }
    
        public void disappear() {
            for (Person friend : friends) {
                friend.friends.remove(this);
            }
        }
    }
    

    The advantage of this approach is that all operations complete in constant expected time.

    This is much better than keeping a linked list of a friendships where finding the number of friends of a single person requires us to go through the list of all 10000 friendships.

    It is also significantly faster than the two-dimensional array described by rogelware, where finding the number of friends requires checking all 2000 other persons for friendship, and removing a person requires clearing the friendship to all 2000 other persons.

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

Sidebar

Related Questions

I need some help in solving this problem. We have a large amount of
i have this problem to find a particular xml node l have post this
i have this problem: ms-access could not delete and i found a potential solution
I have this problem I'm hoping someone knows the answer to. I have an
I have this problem where I open Visual Studio and the internal windows are
I have this problem I've been trying to tackle for a while. I have
I have this problem in my ASP.NET application where I'm seeing some of my
I have this problem that my sites uses alot of ajax and when a
I have this problem containing some inequations and requirement to minimize a value. After
I have this problem decomposing a relation schema into a set of schemas that

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.