Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Industrial Engineering Department IE 211 - Introduction to Algorithms Fall 2020 - Homework # 4 Instructor: Banu Kabakulak, PhD Due Date: January 15th, 2021 until

image text in transcribed
image text in transcribed
Industrial Engineering Department IE 211 - Introduction to Algorithms Fall 2020 - Homework # 4 Instructor: Banu Kabakulak, PhD Due Date: January 15th, 2021 until 23:59 Question 1: (50 pts) Consider the 0/1 Knapsack Problem. The problem can be solved to optimality via a dynamic programming algorithm 1. (25 pts) Use the pseudocode of the dynamic programming (DP) algorithm that we have developed in the lecture. Implement DP in Java to find an optimal solution of 0/1 Knapsack Problem. 2. (25 pts) Randomly generate the value v (1,40], the volume ; [10,30), and set the total volume W = NW - 1. Graphically represent the computation time for the input sizes n = 10,50, 100, 200, 500, Report the console outputs and your Java code scripts. Question 2: (50 pts) Assume that we are given a number and we carry out a sequence of mathematical operations (multiplication, division, subtraction, summation on the number, Consider the stack data structure in Java to store the history of the mathematical operations. Then, use the same stack to revert the mathematical operations on a given number Ex number = 10 Storing history Operation 1: (first operand, type, second operand) = (sumber,,3) Do() returns 10 * 3 = 30, and the current value of number is 30. stack {Operation 1) IE 211 Fall 2020 Homework #4 Operation 2: (first operand, type, second operand) = (number, +, 8) Do() returns 30 + 8 = 38, and the current value of number is 38. stack (Operation 1. Operation 2} Backtracking Last operation in the stack is Operation 2: (30, +, 8). Undo() returns 30, and the current value of number is 30. stack = {Operation 1] Last operation in the stack is Operation 1: (10,3). Undo() returns 10, and the current value of number is 10. stack - Define a class Operation which has fields for the first operand, operation type (+ 1.-,+) and second operand. This class should also implement a method Do(), which returns the result of the operation, and a method Undo(), which returns the first operand's value. . Let us given number - 10 initially and assume this value as the first operand. Randomly generate a operation type from (, /,- +), and a value for the second operand in the range (1, 201 Store this operation in a Stack

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts Of Database Management

Authors: Joy L. Starks, Philip J. Pratt, Mary Z. Last

9th Edition

1337093424, 978-1337093422

More Books

Students also viewed these Databases questions

Question

12-5 How will MIS help my career?

Answered: 1 week ago