![subject](/tpl/images/cats/mat.png)
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](/tpl/images/cats/User.png)
Answers: 1
Another question on Mathematics
![question](/tpl/images/cats/mat.png)
Mathematics, 21.06.2019 18:30
Haruka hiked several kilometers in the morning. she hiked only 66 kilometers in the afternoon, which was 25% less than she had hiked in the morning. how many kilometers did haruka hike in all?
Answers: 3
![question](/tpl/images/cats/mat.png)
Mathematics, 21.06.2019 18:30
The square pyramid has a volume of 441 cubic inches. what is the value of x? 1/7x is the height x is the base
Answers: 2
![question](/tpl/images/cats/mat.png)
Mathematics, 21.06.2019 19:50
Which inequality is equivalent to -3x < -12? x < 4 , x < -4 , x > 4, x > -4
Answers: 1
![question](/tpl/images/cats/mat.png)
Mathematics, 21.06.2019 22:00
Nikita wants to apply for student aid to fund her college education. arrange the steps involved in nikita’s application for financial aid
Answers: 3
You know the right answer?
In mathematical set theory, two sets are considered "disjoint" if they have no elements in common. T...
Questions
![question](/tpl/images/cats/mat.png)
Mathematics, 28.01.2021 05:20
![question](/tpl/images/cats/mat.png)
![question](/tpl/images/cats/mat.png)
![question](/tpl/images/cats/en.png)
English, 28.01.2021 05:20
![question](/tpl/images/cats/mat.png)
![question](/tpl/images/cats/es.png)
Spanish, 28.01.2021 05:20
![question](/tpl/images/cats/mat.png)
![question](/tpl/images/cats/istoriya.png)
![question](/tpl/images/cats/ekonomika.png)
Business, 28.01.2021 05:20
![question](/tpl/images/cats/istoriya.png)
History, 28.01.2021 05:20
![question](/tpl/images/cats/mat.png)
Mathematics, 28.01.2021 05:20
![question](/tpl/images/cats/en.png)
![question](/tpl/images/cats/mat.png)
![question](/tpl/images/cats/mkx.png)
Arts, 28.01.2021 05:20
![question](/tpl/images/cats/obshestvoznanie.png)
Social Studies, 28.01.2021 05:20
![question](/tpl/images/cats/biologiya.png)
![question](/tpl/images/cats/istoriya.png)
History, 28.01.2021 05:20
![question](/tpl/images/cats/mat.png)
Mathematics, 28.01.2021 05:20
![question](/tpl/images/cats/en.png)