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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:51:26+00:00 2026-06-14T17:51:26+00:00

This is an algorithmic question. I have got Dictionary<object,Queue<object>> . Each queue contains one

  • 0

This is an algorithmic question.

I have got Dictionary<object,Queue<object>>. Each queue contains one or more elements in it. I want to remove all queues with only one element from the dictionary. What is the fastest way to do it?

Pseudo-code: foreach(item in dict) if(item.Length==1) dict.Remove(item);

It is easy to do it in a loop (not foreach, of course), but I’d like to know which approach is the fastest one here.

Why I want it: I use that dictionary to find duplicate elements in a large set of objects. The Key in dictionary is kind of a hash of the object, the Value is a queue of all objects found with the same hash. Since I want only duplicates, I need to remove all items with just a single object in associated queue.

Update:

It may be important to know that in a regular case there are just a few duplicates in a large set of objects. Let’s assume 1% or less. So possibly it could be faster to leave the Dictionary as is and create a new one from scatch with just selected elements from the first one… and then deelte the first Dictionary completely. I think it depends on the comlpexity of computational Dictionary class’s methods used in particular algorithms.

I really want to see this problem on a theoretical level because as a teacher I want to discuss it with students. I didn’t provide any concrete solution myself because I think it is really easy to do it. The question is which approach is the best, the fastest.

  • 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-14T17:51:29+00:00Added an answer on June 14, 2026 at 5:51 pm

    It stead of trying to optimize the traversing of the collection how about optimizing the content of the collection so that it only includes the duplicates? This would require changing your collection algorithm instead to something like this

    var duplicates = new Dictionary<object,Queue<object>>;
    var possibleDuplicates = new Dictionary<object,object>();
    foreach(var item in original){
        if(possibleDuplicates.ContainsKey(item)){
           duplicates.Add(item, new Queue<object>{possibleDuplicates[item],item});
           possibleDuplicates.Remove(item);
        } else if(duplicates.ContainsKey(item)){
           duplicates[item].Add(item);
        } else {
           possibleDuplicates.Add(item);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is not really a programming question, more of an algorithmic one. The problem:
I have got one question to print one million prime numbers . I have
Possible Duplicate: optimal algorithm for finding unique divisors I have asked this question before,
This is kind of more generic question, isn't language-specific. More about idea and algorithm
This is more of an algorithmic dilemma than a language-specific problem, but since I'm
I have this algorithm that I want to implement on VB6. Sub Main() dim
My girlfriend got this question in an interview, and I liked it so much
I got this question in an interview and I was not able to solve
Firstly, I realise that this is a very similar question to this one: Which
I recently asked this question https://softwareengineering.stackexchange.com/questions/129076/go-instead-of-c-c-with-cgo and got some very interesting input. However there's

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.