1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Rufina [12.5K]
3 years ago
10

You are given a list of n positive integers a1, a2, . . . an and a positive integer t. Use dynamic programming to design an algo

rithm that examines whether a subset of these n numbers add up to exactly t, under the constraint that you use each ai at most once. If there is a solution, your program should output the subset of selected numbers. Recurrence Relation (and base cases)
Computers and Technology
1 answer:
Anna11 [10]3 years ago
6 0

Answer:

See explaination for the program code

Explanation:

The code below

Pseudo-code:

//each item ai is used at most once

isSubsetSum(A[],n,t)//takes array of items of size n, and sum t

{

boolean subset[n+1][t+1];//creating a boolean mtraix

for i=1 to n+1

subset[i][1] = true; //initially setting all first column values as true

for i = 2 to t+1

subset[1][i] = false; //initialy setting all first row values as false

for i=2 to n

{

for j=2 to t

{

if(j<A[i-1])

subset[i][j] = subset[i-1][j];

if (j >= A[i-1])

subset[i][j] = subset[i-1][j] ||

subset[i - 1][j-set[i-1]];

}

}

//returns true if there is a subset with given sum t

//other wise returns false

return subset[n][t];

}

Recurrence relation:

T(n) =T(n-1)+ t//here t is runtime of inner loop, and innner loop will run n times

T(1)=1

solving recurrence:

T(n)=T(n-1)+t

T(n)=T(n-2)+t+t

T(n)=T(n-2)+2t

T(n)=T(n-3)+3t

,,

,

T(n)=T(n-n-1)+(n-1)t

T(n)=T(1)+(n-1)t

T(n)=1+(n-1)t = O(nt)

//so complexity is :O(nt)//where n is number of element, t is given sum

You might be interested in
Quick!!! Brainliest
xxTIMURxx [149]
D. A technology-and creativity-driven world
7 0
3 years ago
Steve is creating a document with proper nouns, which Word continues to identify as being misspelled.
mash [69]

Answer:

it's D. B and C are correct.

Explanation:

The options are:

A. Skip the Spell Checker.

B. Right-click the noun and choose to Ignore All.

C. Right-click and Add to the dictionary.

D. B and C are correct.

You can either right-click the noun and choose to Ignore all. or you can Right-click and add to the dictionary. And this is because you are correct this time, as a proper noun can have misspelled type of spelling. And this is because it is some other language word, and that's why.

6 0
3 years ago
Read 2 more answers
A popular Voice over Internet Protocol (VoIP) service is ________.
Aloiza [94]
The answer would be Skype
8 0
2 years ago
A data type consisting of numbers, letters and symbols is a _____.
LekaFEV [45]

Answer:

That's the answer

Hope it helps

#brainliest

#heart

#star

#Carryonlearning

4 0
2 years ago
Write a method that finds the cheapest name of apples, and returns back a String stating what the apple name is and how much it
Korolek [52]

The question is incomplete! Complete question along with answer and step by step explanation is provided below.

Question:

Two arrays are given:  

String apples[] = {"HoneyCrisp", "DeliciousRed", "Gala", "McIntosh",  "GrannySmith"};

double prices[] = {4.50, 3.10, 2.45, 1.50, 1.20};

Write a method that finds the cheapest name of apples, and returns back a String stating what the apple name is and how much it costs. The method should take two arrays as two parameters (you do not need to make a two dimensional array out of these arrays).

Answer:

The complete java code along with the output is prrovided below.

Java Code:

public class ApplesCheap

{

   public static String Cheapest(String apples[], double prices[])

 {

       int temp = 0;

       for (int i = 0; i < apples.length; i++)

    {

         if (prices[i] < prices[temp])

          {

               temp = i;

           }

       }

       return apples[temp];

   }

public static void main(String[] args)

{

// define the array of apple names and their prices

  String apples[] = {"HoneyCrisp", "DeliciousRed", "Gala", "McIntosh", "GrannySmith"};

  double prices[] = {4.50, 3.10, 2.45, 1.50, 1.20};

// print the cheapest apple by calling the function Cheapest

  System.out.println("The cheapest apple is: " + Cheapest(apples, prices));

   }

}

Output:

The cheapest apple is: GrannySmith

7 0
2 years ago
Other questions:
  • What is the oldest and most common technique to differentiate information systems?
    8·1 answer
  • What type of software resides on a computer’s hard drive, and controls the CPU and all other activity between components?
    6·1 answer
  • Is this statement true or false?
    12·2 answers
  • Lime is using social media to ask consumers about the qualities they desire in an electric scooter. The firm hopes to develop a
    6·1 answer
  • Statement Widgets or gadgets are _____ programs that appear on the desktop and display little pieces of information such as a ca
    5·1 answer
  • Implement a function getContent() that takes as input a URL (as a string) and prints only the text data content of the associate
    6·1 answer
  • Who put forward the idea of nanotechnology to the world?​
    6·1 answer
  • Your network has four Hyper-V hosts, which are running three domain controllers and about 10 member servers. Three of the member
    10·1 answer
  • How are the number of rows calculated.​
    14·1 answer
  • Frankie used the ps command to find the process id of an application that he needs to stop. What command-line tool should he use
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!