Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are given a collection of coins of various denominations (different monetary

ID: 3840802 • Letter: Y

Question

You are given a collection of coins of various denominations (different monetary values) and are asked to choose some or all of the coins to pay for an item of a given price without needing to be given change - ie the exact amount.

How can this be viewed as a search problem? [5 marks]

You are provided with a class Coin which has a single method getValue. If the problem starts from an array of coins, how would you represent the current state? Your answer should include a class definition showing the needed fields and method signatures. You should not provide method bodies. [10 marks]

Provide the Java code for a method getDaughters in your state representation that given a state, would generate the daughter

states. You will not be penalised for minor syntactic errors.

[10 marks

Explanation / Answer

WE HAVE USE SELECTION SORT AND ACHIVE THIS LOGIC

ublic class SSORT {

    public static int[] SORT(int[] arr){

         

        for (int i = 0; i < arr.length - 1; i++)

        {

            int index = i;

            for (int j = i + 1; j < arr.length; j++)

                if (arr[j] < arr[index])

                    index = j;

      

            int sm = arr[index];

            arr[index] = arr[i];

            arr[i] = sm;

        }

        return arr;

    }

     

    public static void main(String a[]){

         

        int[] arr1 = {1,2,2,1,3,4,5,6};

        int[] arr2 = SORT(arr1);

        for(int i:arr2){

            System.out.print(i);

            System.out.print(", ");

        }

    }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote