Question: The Representation How do you represent a set internally? At first thought it might seem like a simple problem. The trivial solution is to have

The Representation
How do you represent a set internally?
At first thought it might seem like a simple problem. The trivial solution is to have each set be a
collection (e.g. a vector) of objects.
While this seems like a simple solution on face value, it can be horribly inefficient. What if I
wanted to make sets of media objects that were each unmanageably large?
A better solution is to store all possible set members, the so-called Universal or Master set,
within the object as a class (static) member. Each instantiated set would then be simply
composed of a collection of integers, which are simply pointers to the actual objects in the
Master set.
This sounds like a good idea. But there's an even better one. With a static master set, you still
have to initialize it by copying over the supplied elements into it. With an understanding that
you will not change the master set, why not have your client (the instantiator of the Set class)
create and maintain the master set as a vector, and you only deal with integer indices into this
(externally maintained) master set?
4
That's the approach we will take in this quest. Although you don't have to code a lot, most of the
time, I presume, may be taken up by simply wrapping your head around this:
The Set object will contain a pointer to an externally maintained vector of elements we
call the master set. This pointer must be set during set initialization.
Each Set object will contain a vector of integers, each of which is an index in the master
set to a valid element contained in that Set. (See Figure 1)class Set 1
private:
vectoraT?;{??
?**
 The Representation How do you represent a set internally? At first

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!