subject
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?

ansver
Answers: 1

Another question on Mathematics

question
Mathematics, 21.06.2019 16:20
The lengths of nails produced in a factory are normally distributed with a mean of 4.91 centimeters and a standard deviation of 0.05 centimeters. find the two lengths that separate the top 4% and the bottom 4%. these lengths could serve as limits used to identify which nails should be rejected. round your answer to the nearest hundredth, if necessary.
Answers: 3
question
Mathematics, 21.06.2019 19:30
Cone w has a radius of 8 cm and a height of 5 cm. square pyramid x has the same base area and height as cone w. paul and manuel disagree on how the volumes of cone w and square pyramid x are related. examine their arguments. which statement explains whose argument is correct and why? paul manuel the volume of square pyramid x is equal to the volume of cone w. this can be proven by finding the base area and volume of cone w, along with the volume of square pyramid x. the base area of cone w is π(r2) = π(82) = 200.96 cm2. the volume of cone w is one third(area of base)(h) = one third third(200.96)(5) = 334.93 cm3. the volume of square pyramid x is one third(area of base)(h) = one third(200.96)(5) = 334.93 cm3. the volume of square pyramid x is three times the volume of cone w. this can be proven by finding the base area and volume of cone w, along with the volume of square pyramid x. the base area of cone w is π(r2) = π(82) = 200.96 cm2. the volume of cone w is one third(area of base)(h) = one third(200.96)(5) = 334.93 cm3. the volume of square pyramid x is (area of base)(h) = (200.96)(5) = 1,004.8 cm3. paul's argument is correct; manuel used the incorrect formula to find the volume of square pyramid x. paul's argument is correct; manuel used the incorrect base area to find the volume of square pyramid x. manuel's argument is correct; paul used the incorrect formula to find the volume of square pyramid x. manuel's argument is correct; paul used the incorrect base area to find the volume of square pyramid x.
Answers: 3
question
Mathematics, 21.06.2019 21:00
Rewrite the following quadratic functions in intercept or factored form. show your work. f(x) = 3x^2 - 12
Answers: 1
question
Mathematics, 21.06.2019 21:00
Can someone answer this question for me
Answers: 1
You know the right answer?
In mathematical set theory, two sets are considered "disjoint" if they have no elements in common. T...
Questions
question
Mathematics, 26.10.2020 23:40
question
Mathematics, 26.10.2020 23:40
question
Health, 26.10.2020 23:40
question
English, 26.10.2020 23:40
Questions on the website: 13722359