What is the run time of the following piece of code in Big-Oh notation? The first loop runs n times in the worst case. But I am having difficulty in finding run time of nested loop which runs V / deno[i] times to be exact. So I think the total runtime would be O(n* V/deno[i])? Please correct me if I am wrong.
int deno[] = {1, 2, 5, 10, 20, 50, 100, 500, 1000};
int n = sizeof(deno)/sizeof(deno[0]);
// Driver program void findMin(int V) { // Initialize result vector ans;
// Traverse through all denomination
for (int i=n-1; i>=0; i--)
{
// Find denominations
while (V >= deno[i])
{
V -= deno[i];
ans.push_back(deno[i]);
}
}
deno[i]
might take and whatans.push_back()
does, this is pretty much unanswerable. – David Richerby Jan 13 '19 at 11:20