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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:26:23+00:00 2026-05-26T19:26:23+00:00

I have a series of Key value pairs. Each Key has 2 values. Values

  • 0

I have a series of Key value pairs. Each Key has 2 values. Values of Keys may coincide.
Initially, I start with Key1, ValueKey1, ValueKey2 are stored in a set (maybe array).

Now for each consecutive Keyi, I check if Valuei and Valuei+1 are in the set. If any one of them is in the set, then join the set.

Else if both KeyValues are present in a set, discard that key.

How can I implement this thing using C++, I have very little idea, so if possible a code snippet or a hint would be really helpful.

  • 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-26T19:26:24+00:00Added an answer on May 26, 2026 at 7:26 pm

    Are you using or in possession of ‘Algorithms in C++‘ (Sedgewick, 3rd ed.) by any chance?

    The first problem that is encountered in the book is that of connectivity (page 7) , and in it there are multiple implementations of a union-find (quick-union, quick-find, weighted etc) algorithm that uses paired keys.

    Here’s the quick-find version: (This is just a re-type from the book – not tested)

    #include <iostream>
    const int N = 10000;
    int main() {
        int i, p, q, id[N];
        for( i = 0; i < N; i++ ) id[i] = i;
        while( cin >> p >> q ) {
            int t = id[p];
            if ( t = id[q] ) continue;
            for ( i = 0; i < N; i++ )
                if ( id[i] == t) id[i] = id[q];
            cout << " " << p << " " << q << endl;
        }
    }
    

    Just keeps spitting out pairs that aren’t connected (which you could probably invert to get what you want)

    The book has a pretty detailed description of how it works – and I’m guessing that you have it for now.

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

Sidebar

Related Questions

I have a string of key->value pairs in the following colon-separated format: MIME-Version: 1.0
I have a series of JCheckBoxes(1-20) and each is associated with a JTextField(1-20). I
As I understood it before taking this job, XML Uses a series of key-value
<toolkit:Chart Title=Sales Name=ChartSales> <toolkit:Chart.Series> <toolkit:LineSeries Title=Serie1 Name=LineSerie1 IndependentValueBinding={Binding Key} DependentValueBinding={Binding Value} /> <toolkit:LineSeries Title=Serie3
say I have the following YAML file: - key1: value # and so on...
I have a listview that serves as a user-settings table. Each key is the
I have a series of tables which I want to all have an order
I have a series of strings, which are two numbers: 1.782-100.799 -18.107-102.016 -17.504104.059 How
I have a series of PDFs named sequentially like so: 01_foo.pdf 02_bar.pdf 03_baz.pdf etc.
I have a series of functional tests against a web application that correctly run,

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.