
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
thumb_up100%
1. Consider the following dynamic
#include
int find_max(int a, int b)
{
if(a > b)
return a;
return b;
}
int knapsack(int W, int *wt, int *val,int n)
{
int ans[n + 1][W + 1];
int itm,w;
for(itm = 0; itm <= n; itm++)
ans[itm][0] = 0;
for(w = 0;w <= W; w++)
ans[0][w] = 0;
for(itm = 1; itm <= n; itm++)
{
for(w = 1; w <= W; w++)
{
if(wt[itm - 1] <= w)
ans[itm][w] = ______________;
else
ans[itm][w] = ans[itm - 1][w];
}
}
return ans[n][W];
}
int main()
{
int w[] = {10,20,30}, v[] = {60, 100, 120}, W = 50;
int ans = knapsack(W, w, v, 3);
printf("%d",ans);
return 0;
}
Which of the following lines completes the above code?
A. find_max(ans[itm – 1][w – wt[itm – 1]] + val[itm – 1], ans[itm – 1][w])
B. find_max(ans[itm – 1][w – wt[itm – 1]], ans[itm – 1][w])
C. ans[itm][w] = ans[itm – 1][w];
D. none of the mentioned
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- C programming I'm trying to fix memory leak but it kept giving that one error. Where did I go wrong? #include <stdlib.h>#include <stdio.h> void printArray(int *arr, int size){ int i; if (arr != NULL) { for( i = 0; i < size; i++) { // Print each element out printf("%d", *(arr+i)); //Print addresses of each element printf("%p", (arr+i)); //Printing a new line printf("\n"); }} } int main() { // Allows user to specify the original array size, stored in variable n1. printf("Enter original array size: "); int n1 = 0; scanf("%d", &n1); //a- Create a new array *a1 of n1 ints using malloc int *a1 = malloc(n1 * sizeof(int)); //b- Remove comments for if statment below //b- Set each element in a1 to 100 + indexValue ?? if(a1 == NULL){printf("Error! memory not allocated."); exit(0);} int i; for (i = 0; i < n1; i++) { a1[i] = 100 + i; } printf("Printing the first array allocated…arrow_forwardI need help with my Optimizing the intermediate code to improve the efficiency of the generated machine code. I need to improve the effixiency of the generated machine code import java.util.*; public class SimpleCalculator { private final String input; private int position; private boolean hasDivByZero = false; private Map<String, String> symbolTable; private List<String> instructions; public SimpleCalculator(String input) { this.input = input; this.position = 0; this.symbolTable = new HashMap<>(); this.instructions = new ArrayList<>(); } public static void main(String[] args) { SimpleCalculator calculator = new SimpleCalculator("3 + 5 * (2 - 1)"); calculator.parseExpression(); if (calculator.hasDivByZero) { System.out.println("Error: division by zero"); } else { System.out.println("Result: " + calculator.instructions); } } public void parseExpression() { String t1 = parseTerm(); while (true) { String op = null; if (consume('+')) { op = "+"; } else if…arrow_forwardNote: javaarrow_forward
- Q1. 1 and 2arrow_forwardwrite the following usong for loopsarrow_forwardpublic static void main(String[] args) { for(int a = 0; a < n; a++) //n foo(); //n } public static foo() { for(int a = 0; a < n; a++) //n System.out.println(a); } Log Exponent Rule: Consider the following logarithm a(x) = log2 X°. Note that we can rewrite this using the "log roll" as c * log2 X. Since constants are factored out during asymptotic analysis, you can simply drop the constant multiplier (which on a log is it's exponent). • Example f(x) = log2 X6 f(x) becomes6 * log2 X, and O(log2 X) Log Base Rule: You may omit the base of the log and assume its base-2. Transitivity: if a < b< c, then a < c. Related to big , if a = 5x² + 3xand I'm trying to prove that a is less than or equal to (i.e, bounded by) x2, we would write5x? + 3x < c * x2 and find some pair of c, k such that this relationship holds. Using transitivity, 5x? + 3xarrow_forward
- Please help me with this Principles of programming language homework questionarrow_forwardGenerate test cases for the following code by using Basic Path Testing. void sort(int a[ ],int N) { int i,j,p,t; } for(i=0;ia[p]) p=j; if(p!=i) {t=a[p]; a[p]=a[i]; a[i]=t; } Draw CFG. How many basic paths for the c) List the basic paths. d) Generate test cases from it.arrow_forwardWrite a parallel program for the following code /* PROGRAM Sieve */ #include <stdlib.h> #include <math.h> #define n 100 boolean Prime[n+1]; int i,num,loc; main( ) { for (i = 1; i <= n; i++) Prime[i] = TRUE; for (num = 2; num <= Sqrt(n); num++) if (Prime[num]) { loc = num + num; while (loc <= n) { Prime[loc] = False; } } loc = loc + num; }arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education