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 14:00
After applying the composition r0.90 ry to rs what are the coordinates of r' and s'? a.r'(–3, 1),  s'(–3, 5)b.r'(–1, 3),  s'(–5, 3)c.r'(1, 3),  s'(5, 3)d.r'(5, 3),  s'(1, 3)
Answers: 2
question
Mathematics, 21.06.2019 18:00
Kayla has a $500 budget for the school party.she paid $150 for the decorations.food will cost $5.50 per student. what inequality represents the number of students,s, that can attend the party?
Answers: 1
question
Mathematics, 21.06.2019 20:00
Need ! the total ticket sales for a high school basketball game were $2,260. the ticket price for students were $2.25 less than the adult ticket price. the number of adult tickets sold was 230, and the number of student tickets sold was 180. what was the price of an adult ticket?
Answers: 1
question
Mathematics, 21.06.2019 23:00
Each of the following data sets has a mean of x = 10. (i) 8 9 10 11 12 (ii) 7 9 10 11 13 (iii) 7 8 10 12 13 (a) without doing any computations, order the data sets according to increasing value of standard deviations. (i), (iii), (ii) (ii), (i), (iii) (iii), (i), (ii) (iii), (ii), (i) (i), (ii), (iii) (ii), (iii), (i) (b) why do you expect the difference in standard deviations between data sets (i) and (ii) to be greater than the difference in standard deviations between data sets (ii) and (iii)? hint: consider how much the data in the respective sets differ from the mean. the data change between data sets (i) and (ii) increased the squared difference îł(x - x)2 by more than data sets (ii) and (iii). the data change between data sets (ii) and (iii) increased the squared difference îł(x - x)2 by more than data sets (i) and (ii). the data change between data sets (i) and (ii) decreased the squared difference îł(x - x)2 by more than data sets (ii) and (iii). none of the above
Answers: 2
You know the right answer?
In mathematical set theory, two sets are considered "disjoint" if they have no elements in common. T...
Questions
question
Arts, 06.01.2021 02:10
question
English, 06.01.2021 02:10
question
English, 06.01.2021 02:10
Questions on the website: 13722363