Mathematics
Mathematics, 23.05.2020 02:02, cswalke

In mathematical set theory, two sets are considered "disjoint" if they have no elements in common. The following C++ function tests whether two instances of std::set are disjoint. It returns true if the two sets, a and b, are disjoint (they have no elements in common) or false if the two sets are not disjoint (they have at least one element in common).
Checks if two sets, a and b, are disjoint. // a and b are disjoint if and only if they have no elements in common. template bool areDisjoint(std::set& a, std::set& b) { // Iterate through the items in a. for (const T& item : a) { // b. find() == b. end() if and only if the item isn't in b. if (b. find(item) != b. end()) { // If the b contains the current item being checked, then it's in both sets. // Return false (sets aren't disjoint). return false; } } // If no item was in both sets, then return true (the sets are disjoint). return true; }
a. Describe the best case scenario for areDisjoint. Under what conditions will the function return most quickly?
b. Describe the worst case scenario for areDisjoint. Under what conditions will the function take the most time to return?
c. What is the best-case time complexity for areDisjoint in Big-O notation? Use m and n in your answer, as defined above, and explain the reasoning behind your answer.
d. What is the worst-case time complexity for areDisjoint in Big-O notation? Usem and n in your answer, as defined above, and explain the reasoning behind your answer.
e. It will often be the case that set "a" is larger than set "b." How could you modify the implementation of areDisjoint() to improve the worst-case time complexity in this scenario?

answer
Answers: 1

Other questions on the subject: Mathematics

image
Mathematics, 21.06.2019 13:40, jonmorton159
Although changes result from business transactions, the equality of the fundamental bookkeeping equation must remain. t/f
Answers: 2
image
Mathematics, 21.06.2019 16:30, AutumnJoy12
Yoku is putting on sunscreen. he uses 2\text{ ml}2 ml to cover 50\text{ cm}^250 cm 2 of his skin. he wants to know how many milliliters of sunscreen (c)(c) he needs to cover 325\text{ cm}^2325 cm 2 of his skin. how many milliliters of sunscreen does yoku need to cover 325 \text{ cm}^2325 cm 2 of his skin?
Answers: 3
image
Mathematics, 21.06.2019 18:00, edgarsandoval60
What is the equation of this graphed line? enter your answer in slope-intercept form in the box.
Answers: 2
image
Mathematics, 21.06.2019 22:00, MoparorNocar061401
Find two numbers if their sum is 91 and the ratio is 6: 7?
Answers: 1
Do you know the correct answer?
In mathematical set theory, two sets are considered "disjoint" if they have no elements in common. T...

Questions in other subjects: