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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:56:37+00:00 2026-05-27T20:56:37+00:00

I have a relatively large set of data that lends itself very naturally to

  • 0

I have a relatively large set of data that lends itself very naturally to the c#’s dictionary object. Currently, I have 102400 key-value pairs that are being generated semi-dynamically when my program starts up. My problem is that I have to run a great number of lookup operations as fast as possible.

According to This Page the speed of the lookups is directly influenced by the number of key-value pairs in the dictionary. My data is a bit odd in that a great number of different keys lead to the same value. In fact, I have only 4900 distinct values… This means that I have an average of 20 key-value pairs for each distinct value.

My first instinct was to swap the keys for the values (as I only care about the distinct values in the data) then have the old keys in a list or array as the new values. This reduced my dictionary size to 4900 from 102400 key-value pairs, but I can’t see any way to efficiently search all of the lists for a specific value to get the key by.

I know that my description probably got a bit dificult to follow as I switched the keys and values, so I’ve included a mock-up of my data to show you what I mean:

old method:

Key   Value
---   -----
1     1
2     2
3     3
4     1
5     3
6     2
7     2
8     1
9     3
10    2
11    3
12    1

New structure:

Key   Value
---   -----
1     {1,4,8,12}
2     {2,6,7,10}
3     {3,9,5,11}

In my program, I’m going to be given ’11’ and I’ll need to return ‘3’. The first structure is a simple lookup, but is a huge list which seems to be slowing things down… the second adds so much logical overhead to track down which value list I’m looking for that I’ve only seen a reduction in speed trying to implement it.

Am I barking up the wrong tree here? Should I just accept the speed of the larger list, or is there some other way that I can store my data to increase the lookup speed?

  • 1 1 Answer
  • 1 View
  • 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-27T20:56:37+00:00Added an answer on May 27, 2026 at 8:56 pm

    If all keys are distinct and contiguous, then you should consider a simple array; if the keys aren’t contiguous, then a hash map type of structure if they aren’t. This would be approaching O(1) if the hashing function is good, and if they are all integers, shouldn’t take up much space.

    Even then, for 102400 elements, a binary tree lookup would take at most log2(102400) operations per lookup which is 16.64 operations, not exactly slow.

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

Sidebar

Related Questions

Working with a relatively large data set I have a situation where I need
I have a relatively large table (5,208,387 rows, 400mb data/670mb index), all columns i
I have this relatively large numerical application code that may run for a few
I have a relatively large database tables (just under a million rows) that has
I am relatively new to cassandra and its data model. I have a large
I have a relatively simple object with a method that makes an HTTP request.
I have a relatively large 4-deep relational data setup like this: ClientApplication has_many =>
I currently have a relatively large HTML form (100+ fields). I want to take
I have a very large training set (~2Gb) in a CSV file. The file
I have a large set of data saved in a long list. This is

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.