Menu

[solved]-Worst Case Average Case Complexity Respectively Following Code Rand K Generates Random Num Q39071737

What are the worst case and average case complexity,respectively, of the following code? (“rand() % k” generates arandom number in the range 0..k-1 and runs in O(1) time).

vector<int> loadVector(int n){ vector<int> v; for (int i = 0; i < n; ++i) { if (rand() % 2 == 0) for (int j = 0; j < n; ++j) v.push_back(rand() % n); } return v;}

worst: O(n), average:  O(n)

worst: O(n), average: O(n2)

worst: O(n2), average: O(n)

worst: O(n2), average: O(n2)

worst: O(n3),average:  O(n2)

None of the above

Expert Answer


Answer to What are the worst case and average case complexity, respectively, of the following code? (“rand() % k” generates a rand… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *