0

I have a question regarding the analysis of my algorithm. I have coded the following code below:

public class ExactCoinChange {
public static void main(String[] args)  
    { 
        int n = [CHANGE HERE]; 

        System.out.print("Following is minimal number of change for " + n + ": "); 
        findMin(n); 
    } 

public static void findMin(int V) 
{ 
    int coins[] = {1, 5, 10, 25}; 
    int n = coins.length; 

    // Initialize result  
    int ans[] = new int[4]; 
    int count[] = new int[4];

    // Traverse through all coin values  
    for (int i = n - 1; i >= 0; i--) 
    { 
        // Find denominations  
        while (V >= coins[i])  
        { 
            V -= coins[i]; 
            ans[i] = (coins[i]);
            count[i] = count[i] + 1; 
        } 
    } 
    // Print result  
    for (int i = 0; i < ans.length; i++) 
    {    
        if (ans[i] > 0){
            System.out.print(" " + count[i] + " -");
            System.out.print(" ." + ans[i] + " |"); 
         }
      } 
   }     
}

The question and problem I am facing is that I want to figure out the range for the number of basic operations performed by the algorithm in making changes for n > 0 cents? How can I figure out the range? Is it kinda like a recurrence relation? Any leads help. Thank you.

0 Answers0