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

Other questions on the subject: Mathematics

image
Mathematics, 21.06.2019 14:30, nunnielangley0
The contents of 3838 cans of coke have a mean of x¯¯¯=12.15x¯=12.15. assume the contents of cans of coke have a normal distribution with standard deviation of σ=0.12.σ=0.12. find the value of the test statistic zz for the claim that the population mean is μ=12.μ=12.
Answers: 1
image
Mathematics, 21.06.2019 16:30, joThompson
You are cycling around europe with friends. you book into a hostel and you ask the owner what the ratio of men to women is currently staying there. there are 24 men and 6 women. what is the ratio of men to women in its simplest form?
Answers: 2
image
Mathematics, 21.06.2019 22:30, zacksoccer8279
Assume that y varies inversely with x. if y=1.6 when x=0.5 find x when y=3.2 acellus answer
Answers: 2
image
Mathematics, 22.06.2019 02:00, nadinealonzo6121
Identify the percent of change as an increase or a decrease. 75 people to 25 people response - correct increase decrease question 2 find the percent of change. round to the nearest tenth of a percent.
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 in other subjects:

Konu
Mathematics, 13.10.2020 14:01