Can someone please help me with finding the complexity of below code:
/*The code is of finding all possible combinations of coins (given in array,
each having infinite supply) that sum upto given target value.*/

void solve(int index[], int arr[], int target, int cursum, int n, int sz)
{
 cnt++;

 if(cursum>target)
  return;

 if(cursum==target)
  print(arr,index,n); //Assume O(1)  Time operation

 for(int i=index[n];i<sz;i++)
 {
  index[n+1]=i;
  solve(index,arr,target,cursum+arr[i],n+1,sz);
 }
}

void solve(int arr[], int target, int len)
{
 int index[100];
 index[0]=0;
 solve(index,arr,target,0,0,len);
}

int main()
{
 int arr[]={5,15,25}; //we have coins of 5, 15, 25 paise, each having
infinite supply
 int sum = 0;
 int len = sizeof(arr)/sizeof(arr[0]);
 int target = 100; //we want combination of given coins too make 100 paise

 solve(arr,100,len);
}
-- 
Regards,*
Aanchal Goyal*.

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to