AoT 02 Structure Flowchart Assignment 2
AoT 02 Structure Flowchart Assignment 2
1. There are two important skills of a good software engineer (a) consider all corner cases and (b) try to
improve the speed of the code. In the following example for the function intersection(A, B), see how we
have improved the original code with the corner cases as well as improved the speed.
Now think about the following operations on sets we have already written in class. Please write the
additional code before the start of the iteration to make those functions “better”. Copy the remaining
code from class slides and improve the original code.
2. We know how to do AGGREGATIONS (sum, min, max, prod) on Sets and OPERATIONS (belongsTo,
intersection, union, difference, subset) on Sets. We will now combine the two into a single function. First
one is an example. Note how these can be done in two ways.
PREPARATION: First write the following functions from class notes (plus above improvements)
• sum_of_set(A), prod_of_set(A), min_of_set(A), max_of_set(A)
• intersection(A, B), union(A, B),
difference(A, B):
3. Let’s say you are given two Sets: 𝐀 = {𝑎, 𝑏, 𝑐} and 𝐁 = {𝑝, 𝑞}. Let’s say we want to compute the following
function called the join(A, B) of the two sets as follows
𝑗𝑜𝑖𝑛(𝐀, 𝐁) = 𝑎𝑝 + 𝑎𝑞 + 𝑏𝑝 + 𝑏𝑞 + 𝑐𝑝 + 𝑐𝑞
i.e. we want to take EACH element in A and multiply with EACH element of B and then add all the products.
(a) Below is the code for join(A, B). Please fill in the blanks. This is called a NESTED for loop (one for loop
inside another).
(b) Fill the blanks in the below flowchart with the correct statements. Fill the boxes with Yes or No.
(d) What is the value of: 𝑗𝑜𝑖𝑛({3}, {3}). Is it true that 𝑗𝑜𝑖𝑛({𝑥}, {𝑥}) = 𝑥 !
(f) What is the value of: 𝑗𝑜𝑖𝑛({3}, {5}). What is 𝑗𝑜𝑖𝑛({𝑥}, {𝑦})?
(c) If we want to compute (𝑎 + 𝑏)! how can we use the join function?
(d) If we want to compute (𝑎 + 𝑏 + 𝑐)! how can we use the join function?