Sets - Chapter 8 Flashcards

1
Q

A blank is a collection of distinct elements

A

set

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

A set blank operation adds an element to the set, provided an equal element doesn’t already exist in the set.

A

add

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

A set is an blank collection

A

unordered

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Set blank may be primitive data values, such as numbers or strings, or objects with numerous data members.

A

elements

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

When storing objects, set implementations commonly distinguish elements based on an element’s blank: A primitive data value that serves as a unique identifier for the element.

A

key value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Sets are commonly implemented to use keys for blank element types.

A

all

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

When storing objects, the set retrieves an object’s blank via an external function or predetermined knowledge of which object property is the key value.

A

key

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

When storing blank data values, each primitive data value’s key is itself.

A

primitive

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Given a key, a set blank operation removes the element with the specified key from the set.

A

remove

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Given a key, a set blank operation returns the set element with the specified key, or null if no such element exists.

A

search

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

The search operation can be used to implement a blank.

A

subset test

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

A set X is a blank of set Y only if every element of X is also an element of Y.

A

subset

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

The blank of sets X and Y, denoted as X ∪ Y, is a set that contains every element from X, every element from Y, and no additional elements.

A

union

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

The blank of sets X and Y, denoted as X ∩ Y, is a set that contains every element that is in both X and Y, and no additional elements.

A

intersection

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

The blank of sets X and Y, denoted as X \ Y, is a set that contains every element that is in X but not in Y, and no additional elements.

A

difference

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

The blank and blank operations are commutative, so X ∪ Y = Y ∪ X and X ∩ Y = Y ∩ X. The blank operation is not commutative.

A

union and intersection
difference

17
Q

A blank operation on set X produces a subset containing only elements from X that satisfy a particular condition

A

filter

18
Q

The condition for filtering is commonly represented by a blank: A function that takes an element as an argument and returns a Boolean value indicating whether or not that element will be in the filtered subset.

A

filter predicate

19
Q

A blank operation on set X produces a new set by applying some function F to each element.

A

map

20
Q

A blank is a set that can change after being constructed.

A

dynamic set

21
Q

A blank is a set that doesn’t change after being constructed

A

static set

22
Q

A set can be implemented in Python using a blank to store set elements. In practice, a balanced BST or hash table is often used to efficiently implement a set, but a BST will suffice for all necessary set operations.

A

binary search tree (BST)

23
Q

The set implementation supports iterating through all items in the set. The Set class’s blank instance method constructs and returns a BSTIterator object referencing the minimum node in the tree.

A

__iter__()

24
Q

The Set class’s blank method takes an optional argument for a get-key function.

A

__init__()

25
Q

The blank takes an element as an argument and returns the element’s key. If no get-key function argument is passed to the Set constructor, then a default lambda function is used that takes an element as an argument and returns the same element as the key. The get-key function is used for comparing elements in the set’s BST implementation.

A

get-key function

26
Q

A blank provides a shorthand notation for creating a function object. An expression of the form:
get_key = lambda x: x

assigns get_key as a function object with functionality equivalent to:
def get_key(x):
return x

A lambda function allows a variable to reference a function without declaring the function as global or an instance method.

A

lambda function

27
Q

The Set class implements standard blank in the add(), remove(), and search() methods. The __len__() method returns the set’s length by counting the number of nodes in the BST. The remaining methods implement common set operations such as difference(), filter(), intersection(), map(), and union().

A

BST functionality

28
Q

Builds a new set by adding elements returned from a function. The function is passed as an argument and is called for each element in the instance set.

A

map

29
Q

Allows a Set object to be iterated through in a for loop.

A

__iter__() method

30
Q

Builds and returns the set of elements that exist only in both sets.

A

intersection

31
Q

Builds and returns the set of elements that exist in 1 or both sets.

A

Union

32
Q

Builds and returns the set of elements that exist only in the instance set, and not in the other set.

A

difference

33
Q

Builds and returns the set of elements from the instance set that satisfy the predicate.

A

filter