I'm reading the first chapter of Algorithms in C++: Part 1 - 4 Fundamentals, Data Structures, Sorting, Searching and have a question regarding an exercise they've given.
The exercise question is this:
Q) Describe a simple method for counting the number of sets remaining after using the union and find operations to solve the connectivity problem as described in the text.
The only answer I can think of is: For every union you make, the number of sets remaining decreases by 1.
I'm not sure if that's the answer they're looking for because there's no solutions manual or answer guide at the back.
That sounds like half a good answer to me. I'd have to complain that you are using the variable 'sets' without initializing it, however. ;) In other words, what does the value of 'sets' start at?