The nature of the data structure set _ set and the nature of the data structure set

Source: Internet
Author: User
Tags benchmark

The nature of the data structure set _ set and the nature of the data structure set

A set is an unordered aggregation of different objects (called members.

Two important features of a set: 1. The members are disordered; 2. Each member only appears once in the set.

Set is an important part of discrete mathematics, which has a deep relationship with computer science.

In computer science, we use collections to classify data, especially when we plan to associate it with other data.

The C language does not support collections, but is implemented as an abstract data type.

Set Definition

The symbol of the set: ∪ ∈ Φ ∞.

1. Empty set: a set that does not contain any members.

Global: all possible members of a set (sometimes difficult to define !).

It can be expressed:

S = U indicates global S = Phi indicates empty set

2. Set equal: if the two sets contain identical members, the two sets are equal.

For example, if S1 = {1, 2, 3}, S2 = {1, 2, 3}, S3 = {1, 2, 4}, S1 is S2, but S1 is not S3. Expressed:

S1 = S2 indicates that S1 and S2 are equal; S1 = S3 indicates that S1 and S3 are not equal.

3. subset: If set S2 contains all the members of another set S1, then S1 is the subset of S2.

For example, S1 = {1, 3}, S2 = {1, 2, 3}, S3 = {1, 2}, S1 is a subset of S2, but S1 is not a subset of S3. Expressed:

S1 ipvs2 indicates that S1 is a subset of S2;

Basic operations on a set

1. The Union of S1 and S2 is also a set, which is recorded as Su. It contains all the members in S1 and S2.

For example, if the set S1 = {1, 2, 3}, S2 = {3, 4}, Su = {1, 2, 3 }. Expressed:

Su = S1 ipvs2.

2. The intersection of S1 and S2 is also a set, which is recorded as Si. It only contains members that exist in S1 and S2 at the same time.

For example, if the set S1 = {1, 2, 3}, S2 = {1, 2}, Si = {1, 2 }. Expressed:

Si = S1 ipvs2.

3. The difference set of the Two sets is also a set, which is recorded as Sd. It only contains members that have appeared in S1 and do not belong to S2.

For example, if the set S1 = {1, 2, 3}, S2 = {3, 4}, Sd = {1, 2 }. Expressed:

Sd = S1-S2.

Set nature

1. The result of intersection between a set and an empty set must be an empty set. The Union result of a set and an empty set is the original set itself.

These actions are causedEmpty set law of a setIndicates:

S ∩ Phi = Phi

S ∪ Phi = S

2. The result of intersection with the set itself is the set itself. Similarly, the result of the Union with the set itself is also the set itself.

This behavior is causedIdempotence of a setDescription:

S ∩ S = S

S ∪ S = S

3. The intersection of set S1 and set S2 is equivalent to the intersection of set S2 and set S1. The same principle applies to union.

This behavior is causedExchange law of a setDescription:

S1 1_s2 = S2 1_s1

S1 1_s2 = S2 1_s1

4. the intersection of a set can be solved in any order. The same principle applies to union.

This behavior is causedUnion law of a setIndicates:

S1 benchmark (S2 release S3) = (S1 release S2) Release S3

S1 benchmark (S2 release S3) = (S1 release S2) Release S3

5. The result of the union of a set and the other two sets can be solved in one allocation method. The same principle applies to solving the combination of the intersection of a set and the other two sets.

This behavior is causedSet allocation LawDescription:

S1 proposal (S2 release S3) = (S1 release S2) proposal (S1 release S3)

S1 benchmark (S2 release S3) = (S1 release S2) Release S3

6. The result of intersection between a set and the set and another set is equal to the set itself. The same principle applies to solving the result of merging the intersection of a set and the Set and the other set.

This behavior is causedSet merging LawDescription:

S1 round (S1 1_s2) = S1

S1 round (S1 1_s2) = S1

7. Solve the intersection or union difference between a set and the other two sets (Morgan Law):

S1-(S2 release S3) = (S1-S2) release (S1-S3)

S1-(S2 release S3) = (S1-S2) release (S1-S3)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.