ArticleslgStudy

science

Set (abstract data type)

Set (abstract data type) is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Set (abstract data type) rather than just read about it. In short: In computer science, a set is an abstract data type that can store distinct values, without any particular order. It is a computer implementation of the mathematical concept of a finite set.

Key takeaways

  • Set (abstract data type) belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Set (abstract data type) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Set (abstract data type) from memory before moving on to harder problems.

Reference excerpt

In computer science, a set is an abstract data type that can store distinct values, without any particular order. It is a computer implementation of the mathematical concept of a finite set. Unlike most other collection types, rather than retrieving a specific element from a set, one typically tests a value for membership in a set. Some set data structures are designed for static or frozen sets that do not change after they are constructed. Static sets allow only query operations on their elements — such as checking whether a given value is in the set, or enumerating the values in some arbitrary order. Other variants, called dynamic or mutable sets, allow also the insertion and deletion of elements from the set. A multiset is a special kind of set in which an element can appear multiple times in the set.

Type theory In type theory, sets are generally identified with their indicator function (characteristic function): accordingly, a set of values of type A {\displaystyle A} may be denoted by 2 A {\displaystyle 2^{A}} or P ( A ) {\displaystyle {\mathcal {P}}(A)} . (Subtypes and subsets may be modeled by refinement types, and quotient sets may be replaced by setoids.) The characteristic function F {\displaystyle F} of a set S {\displaystyle S} is defined as:

F ( x ) = { 1 , if x ∈ S 0 , if x ∉ S {\displaystyle F(x)={\begin{cases}1,&{\mbox{if }}x\in S\\0,&{\mbox{if }}x\not \in S\end{cases}}}

In theory, many other abstract data structures can be viewed as set structures with additional operations and/or additional axioms imposed on the standard operations. For example, an abstract heap can be viewed as a set structure with a min(S) operation that returns the element of smallest value.

Operations

Core set-theoretical operations One may define the operations of the algebra of sets:

union(S,T): returns the union of sets S and T. intersection(S,T): returns the intersection of sets S and T. difference(S,T): returns the difference of sets S and T. subset(S,T): a predicate that tests whether the set S is a subset of set T.

Static sets Typical operations that may be provided by a static set structure S are:

is_element_of(x,S): checks whether the value x is in the set S. is_empty(S): checks whether the set S is empty. size(S) or cardinality(S): returns the number of elements in S. iterate(S): returns a function that returns one more value of S at each call, in some arbitrary order. enumerate(S): returns a list containing the elements of S in some arbitrary order. build(x1,x2,…,xn,): creates a set structure with values x1,x2,...,xn. create_from(collection): creates a new set structure containing all the elements of the given collection or all the elements returned by the given iterator.

Dynamic sets Dynamic set structures typically add:

create(): creates a new, initially empty set structure. create_with_capacity(n): creates a new set structure, initially empty but capable of holding up to n elements. add(S,x): adds the element x to S, if it is not present already. remove(S, x): removes the element x from S, if it is present. capacity(S): returns the maximum number of values that S can hold. Some set structures may allow only some of these operations. The cost of each operation will depend on the implementation, and possibly also on the particular values stored in the set, and the order in which they are inserted.

Additional operations There are many other operations that can (in principle) be defined in terms of the above, such as:

pop(S): returns an arbitrary element of S, deleting it from S. pick(S): returns an arbitrary element of S. Functionally, the mutator pop can be interpreted as the pair of selectors (pick, rest), where rest returns the set consisting of all elements except for the arbitrary element. Can be interpreted in terms of iterate. map(F,S): returns the set of distinct values resulting from applying function F to each element of S. filter(P,S): returns the subset containing all elements of S that satisfy a given predicate P. fold(A0,F,S): returns the value A|S| after applying Ai+1 := F(Ai, e) for each element e of S, for some binary operation F. F must be associative and commutative for this to be well-defined. clear(S): delete all elements of S. equal(S1', S2'): checks whether the two given sets are equal (i.e. contain all and only the same elements). hash(S): returns a hash value for the static set S such that if equal(S1, S2) then hash(S1) = hash(S2) Other operations can be defined for sets with elements of a special type:

sum(S): returns the sum of all elements of S for some definition of "sum". For example, over integers or reals, it may be defined as fold(0, add, S). collapse(S): given a set of sets, return the union. For example, collapse({{1}, {2, 3}}) == {1, 2, 3}. May be considered a kind of sum. flatten(S): given a set consisting of sets and atomic elements (elements that are not sets), returns a set whose elements are the atomic elements of the original top-level set or elements of the sets it contains. In other words, remove a level of nesting – like collapse, but allow atoms. This can be done a single time, or recursively flattening to obtain a set of only atomic elements. For example, flatten({1, {2, 3}}) == {1, 2, 3}. nearest(S,x): returns the element of S that is closest in value to x (by some metric). min(S), max(S): returns the minimum/maximum element of S.

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Set (abstract data type)

Start with the simplest possible case. Write down what Set (abstract data type) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Set (abstract data type) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Set (abstract data type) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Set (abstract data type)

In research
Set (abstract data type) appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Set (abstract data type) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Set (abstract data type) is common in secondary-school and first-year university syllabi. It links to neighbouring topics Abstract data types, Composite data types, Data types, so understanding it makes those chapters shorter.
In everyday life
Look for Set (abstract data type) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Set (abstract data type) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Set (abstract data type) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Set (abstract data type) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Set (abstract data type) in simple terms?

In computer science, a set is an abstract data type that can store distinct values, without any particular order. It is a computer implementation of the mathematical concept of a finite set.

Why does Set (abstract data type) matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Set (abstract data type)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Set (abstract data type).

Tags

  • Abstract data types
  • Composite data types
  • Data types

Keep exploring