Practice Hub
Practice fundamental math and programming concepts for Data Science at The George Washington University.
What is the cardinality of \lvert \mathcal{A} \times \mathcal{B} \times \mathcal{C} \rvert?
\mathcal{A} = \{a, b, c\}, \ \mathcal{B} = \{1, 2\}, \ \mathcal{C} = \{\text{I}, \text{II}, \text{III}\}
The cardinality of the Cartesian product \mathcal{A} \times \mathcal{B} \times \mathcal{C} is the product of the cardinalities of the individual sets:
\begin{align*} \lvert \mathcal{A} \times \mathcal{B} \times \mathcal{C} \rvert &= \lvert \mathcal{A} \rvert \cdot \lvert \mathcal{B} \rvert \cdot \lvert \mathcal{C} \rvert \\ &= 3 \cdot 2 \cdot 3 \\ &= 18 \end{align*}
What are the elements of \mathcal{A}^3?
\mathcal{A} = \{1,2\}
The correct answer is \{ (1,1,1), (1,1,2), (1,2,1), (1,2,2), (2,1,1), (2,1,2), (2,2,1), (2,2,2) \} because the cartesian product \mathcal{A}^3 consists of all ordered triples where each element of the triple is taken from the set \mathcal{A}.
Since \mathcal{A} has 2 elements, there are 2^3 = 8 possible ordered triples.
Suppose we have the following function f:\mathcal{A} \to \mathcal{B} defined as follows:
\mathcal{A} = \{ 0, 1, 2 \}, \ \mathcal{B} = \{ 2, 3, 4, 5 \}, \ f = \{ (0, 2), (0, 4), (1, 2), (1, 5), (2, 3) \}
Find f(2).
To find f(2), we need to look at the pairs in the function definition where the first element is 2. From the given function f, we see that the only pair with 2 as the first element is (2, 3). Therefore, f(2) = 3.
Suppose we have the following function f:\mathbb{N} \to \mathbb{Z}. What is the domain, codomain and range of this function?
The correct answer is domain: \mathbb{N}, codomain: \mathbb{Z}, range: \mathbb{N}. The function f is defined as:
f:\underbrace{\mathbb{N}}_{\text{domain}} \to \underbrace{\mathbb{Z}}_{\text{codomain}};
The range is the set of all actual outputs of the function. Since f maps natural numbers to natural numbers, the range is \mathbb{N}.
Suppose the following functions are defined:
f:\mathbb{N} \to \mathbb{Z}, \ \ g:\mathbb{R} \to \mathbb{Z}
Is f=g?
The answer is False, since the domains of f and g are different. Two functions are equal if they have the same domain, codomain, and output for every input in the domain.
Given the following function f:\mathcal{A} \to \mathcal{B} with:
\mathcal{A} = \{1, 2, 3\}, \ \ \mathcal{B} = \{a, b, c, d\}
Which of the following sets represents a function f that is neither injective nor surjective?
The correct answer is the second option f = \{(1, a), (2, a), (3, b)\} because it is not injective (both 1 and 2 map to ‘a’) and not surjective (elements ‘c’ and ‘d’ in \mathcal{B} are not mapped to by any element in \mathcal{A}).
Suppose the following functions:
f: \mathbb{R} \to \mathbb{Z}, \ \ g: \mathbb{Z} \to \mathbb{N};
What is the composite function g \circ f?
The correct answer is g \circ f: \mathbb{R} \to \mathbb{N} because the output of f (which is in \mathbb{Z}) becomes the input of g (which takes inputs from \mathbb{Z}), and the output of g is in \mathbb{N}. Therefore, the composite function g \circ f takes inputs from \mathbb{R} and produces outputs in \mathbb{N}.
The function f:\mathbb{Z} \times \mathbb{Z} \to \mathbb{Z} \times \mathbb{Z} defined by f(a,b) = (a + b, a + 2b) is bijective. Find f^{-1}(a,b)
The correct answer is f^{-1}(a,b) = (2a - b, b - a). This can be found by solving the following system of equations:
\begin{align*} x + y &= a \\ x + 2y &= b \end{align*}
Subtracting the first equation from the second gives:
\begin{align*} x + y &= a \\ y &= b - a \end{align*}
Substituting this value of y into the first equation gives:
\begin{align*} x &= 2a - b \\ y &= b - a \end{align*}
Thus, the inverse function is given by:
f^{-1}(a,b) = (2a - b, b - a)
You can confirm by checking the composite function f(f^{-1}(a,b)) = (a,b).
\begin{align*} f(f^{-1}(a,b)) &= f(2a - b, b - a) \\ &= ((2a - b) + (b - a), (2a - b) + 2(b - a)) \\ &= (a, b) \end{align*}
Which of the following represents the elements of this set?
\{x \in \mathbb{Z}: x^2 - 2 = 0\}
The \emptyset is the correct answer given that there are no integers x such that x^2 - 2 = 0. The solutions to the equation x^2 - 2 = 0 are x = \sqrt{2} and x = -\sqrt{2}, neither of which are integers. Therefore, the set contains no elements.
Which of the shaded regions matches the following expression?
(\mathcal{A} \cup \mathcal{B}) \cap \mathcal{C}
The correct answer is the third option. We first take the union of sets \mathcal{A} and \mathcal{B}, which includes all elements that are in either set. Then, we find the intersection with set \mathcal{C}, which includes only those elements that are also in set \mathcal{C}.
Find \bar{\mathcal{A}}, given:
\mathcal{A} = \{1,2,3\}, \ \ \mathcal{U} = \{0,1,2,3,4,5\}
The correct answer is \{0, 4, 5\}. This is the complement of set \mathcal{A} with respect to the universal set \mathcal{U}. The complement \bar{\mathcal{A}} includes all elements in \mathcal{U} that are not in \mathcal{A}.
Which of the following is not a set?
The set \mathcal{A} is not a set because it contains the element 3 twice. In set theory, sets cannot have duplicate elements; each element must be unique.
What is the cardinality of the following set:
\lvert \mathcal{A} \rvert = \{ \{ \} \}
The set \mathcal{A} contains one element, which is the empty set \{ \}. Therefore, the cardinality of the set \mathcal{A} is 1.
The following sets are equal:
\{ \ldots -2, -1, 0, 1, 2, \ldots \} = \{ 0, -1, 1, -2, 2, \ldots \}
The two sets are equal because they contain the same elements. The first set lists all integers, while the second set rearranges them. Therefore, the statement is true.
Does the following element belong to the set:
\{\} \in \{1, 2, 3, \ldots\}
The correct answer is False because the empty set \{\} is not one of the elements in the set \{1, 2, 3, \ldots\}. The elements of the set are the natural numbers starting from 1, and the empty set is not included among them.
Determine whether \pi is an element of the set of real numbers \mathbb{R}:
\pi \in \mathbb{R}
The expression \pi \in \mathbb{R} is True given that \pi (approximately 3.14159) is a real number. The set of real numbers, denoted by \mathbb{R}, includes all rational and irrational numbers, and since \pi is an irrational number, it belongs to the set of real numbers.
List the following elements of this set:
\{ \mathcal{X} : \mathcal{X} \subseteq \{\text{Python}, \text{R}, \text{SQL}\} \ \text{and} \ \lvert \mathcal{X} \rvert = 2 \}
The correct answer is \big\{\, \{\text{Python}, \text{R}\}, \{\text{Python}, \text{SQL}\}, \{\text{R}, \text{SQL}\} \,\big\} since these are the only subsets of the set \{\text{Python}, \text{R}, \text{SQL}\} that have exactly 2 elements.
Calculate the slope from these two points (2, 3) and (5, 11).
An event has probability P(A) = 0.34. Compute the probability of the complement:
P(A^c) = 1 - P(A)
Compute the mean of the data list.
Create a 3 \times 3 identity matrix I as a list of lists.
A student received the following grades and credit hours for three courses. Compute the GPA using the formula:
\text{GPA} = \frac{\sum (\text{grade} \times \text{credits})}{\sum \text{credits}}
Two points are represented as tuples u and v. Compute the Euclidean distance between the points using the formula:
\| \mathbf{u} - \mathbf{v} \|_2 = \sqrt{ \sum_{i=1}^n (u_i - v_i)^2 }
Compute the range of the data list.
Calculate the percentage change if price goes from 120\$ to 150\$ (answer should be in decimal format; i.e. 0.3 for 30\% )
A student has grades: 80 (weight 30\%), 90 (weight 50\%), 70 (weight 20\%). Calculate the grade of the student.
Two independent events A and B have probabilities P(A)=0.3 and P(B)=0.5. Calculate the probability that both events occur P(A \cap B).
A population of 1000 grows at 5\% per year, compounded annually. Calculate population after 3 years using:
P = P_{0}*(1 + r)^t
A person weighs 72 kg and is 1.78 meters tall. Calculate their Body Mass Index (BMI) using:
\text{BMI} = \frac{\text{weight}}{\text{height}^2}
Convert 21^\circ C to Fahrenheit using:
F = C \times \frac{9}{5} + 32
Compute the z-score for a value of x = 87, with mean \mu = 75 and standard deviation \sigma = 8:
z = \frac{x - \mu}{\sigma}
A dataset has a standard deviation of \sigma = 6.5. Compute the variance:
\sigma^2 = \sigma \times \sigma
You are given a list of exam_scores. Compute the median of this dataset using indexing.
Assign a class based on two features:
“Class A” if feature1 is greater than 5 and feature2 is less than or equal to 3,
“Class B” if feature1 greater than 5 and feature2 greater than 3,
otherwise “Class C”.
Compute the expected value \mathbb{E}[X] of a discrete random variable X with outcomes x_i and probabilities p_i:
\mathbb{E}[X] = \sum_i x_i \ p_i
You are given an list of data. Compute the third quartile (Q3) using indexing.
Sort the list of data below and return the number that sits 25\% of the way into the sorted list.
Given a 2 \times 3 matrix represented as a list of lists. Access the element a_{2,3}.
A product_code was entered with an extra character “#”. The “#” is an error. Create a cleaned version of the string where the “#” is removed.
You are given a category “A”, “B”, or “C”. Create a one-hot encoded list of length 3, where:
category A → [1,0,0]
category B → [0,1,0]
category C → [0,0,1]
Threshold the prediction of whether to buy or not by checking whether the probability is greater than 50\%:
Determine if the model prediction is correct by comparing predicted and actual values:
Compute the ReLU function of x by following the formula:
\text{ReLU}(x) = \begin{cases} x, & \text{if } x > 0 \\ 0, & \text{if } x \le 0 \end{cases}