954,499 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Implementation of Union find Algorithm

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

Now for each consecutive Keyi, i check if Valuei, 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 less idea, so i would suggest if possible a code snippet or a hint would be really helpful.

Thanks

typedefcoder
Newbie Poster
4 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

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

Now for each consecutive Keyi, i check if Valuei, 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 less idea, so i would suggest if possible a code snippet or a hint would be really helpful.

Thanks


Any help? Is it way too difficult ? :(

typedefcoder
Newbie Poster
4 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

I don't get it. So you say you have a series of key value pairs with 2 values per key, something like this: key => [value1, value2]. Then you loop thru the keys, looking if value1 or value2 of that key are in some set; what set would that be?

xfbs
Light Poster
33 posts since Nov 2011
Reputation Points: 6
Solved Threads: 2
 
I don't get it. So you say you have a series of key value pairs with 2 values per key, something like this: key => [value1, value2]. Then you loop thru the keys, looking if value1 or value2 of that key are in some set; what set would that be?


The problem exactly is.I have an array of numbers.
For any element in the array when i run a function it gives me two values(int).


Now for each element in the array if bot the corresponding values are present in the set we discard it, else if we have one value we add that array element to our solution. else if we have no match found among the two, we make another new set.

Now if we read another array element we check its entry in both the sets created.. and so on...

typedefcoder
Newbie Poster
4 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: