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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:20:25+00:00 2026-05-27T13:20:25+00:00

Consider that I have a map of sets of values to values, in Java

  • 0

Consider that I have a map of sets of values to values, in Java the type of this map would be:

Map<Set<Object>, Object> setToObjMap;

Given a new set of objects set, I wish to find all values in the setToObjMap where the associated key is a subset of a “search set”.

So, for example, if my map was:

["telephone", "hat"] -> "book"
["laugh", "fry", "mouse"] -> "house"
["dog", "cat"] -> "monster"

Then, given the search set ["telephone", "hat", "book", "dog", "cat"] I would retrieve the values “book” and “monster”.

In practice there may be tens of thousands of entries in the setToObjectMap, with tens of thousands of possible values in the sets. The search set will typically have around 10 elements.

I’m hoping there is an efficient way to do this that doesn’t require iterating through all keys in the map. Can anyone offer any suggestions?

  • 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-27T13:20:26+00:00Added an answer on May 27, 2026 at 1:20 pm

    You can create a lookup data structure

    Map<String,List<Finder>>
    

    With Finder having an int count and max, and a res word. Take note that the list is there to take care of the case where many sets in setToObjMap can share the same word, which is not in your examples.

    "telephone" -> [{res:"book",count=0,max=2}]
    "hat" -> same object as above
    "laugh" -> [{res:"house",count=0,max=3}]
    ...
    

    This lookup collection is quick to build and even quicker to flush after a lookup.

    The lookup algorithm iterates through set, for each word, and each Finder for this word, it increases the count variable. Second pass, take all values of the lookup map, if count==max, put res in the result.

    Init algorithm:

    for Entry e in setToObjMap
      Finder f = new Finder(e.value, 0, e.key.size) // res, count, max
      for String word in e.key
        lookup.get(word).add(f)
    

    Lookup algorithm:

    for String word in set
      for Finder f in lookup.get(word)
        f.count ++
    for Finder f in lookup.values()
      if (f.count==f.max)
        res.add(f.res)
    

    Reset algorithm:

    for Finder f in lookup.values()
        f.count = 0
    

    As for the complexity, if n is the number of elements in set and m the number of values in setToObjMap, the complexity will be O(n+m)

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

Sidebar

Related Questions

I have what I would consider a small sized iPhone app that uses SQLite.
Consider this scenario. I have my own website, that I use as my identifier,
Consider this: map fromEnum $ zipWith (==) aaaa abaa -- [1,0,1,1] It would be
Consider that I have a transaction: BEGIN TRANSACTION DECLARE MONEY @amount SELECT Amount AS
Lets consider that I have a public property called AvatarSize like the following, public
Assume that we have multiple arrays of integers. You can consider each array as
I have a configuration file that I consider to be my base configuration. I'd
Let's consider we have QWidget that contains QTableWidget (only). So we want to resize
Consider following scenario: I have RESTful URL /articles that returns list of articles user
I have a single AMQ queue that receives simple messages with string body. Consider

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.