
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN: 9780133594140
Author: James Kurose, Keith Ross
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
thumb_up100%
I’m meeting help with part C of this problem which is finding a recursive solution. The first picture shows you the problem and the second picture is the recursive solution that I have developed which is not working. Any help would be appreciated.

Transcribed Image Text:4. Suppose that we decided to add a deli option to our restaurant where we build sand-
wiches by weight. We want to know what the most expensive sandwich configuration
for a given weight is. Assuming that we have an infinite supply of items, define a
recursive solution that would reflect the maximum cost of a sandwich for a given
CS 3103- Algorithms
2
Fall 2022
weight. You may assume that it is possible for us to place multiple of a given item in
the same box.
a) Characterize the optimal substructure of the problem.
b) Explain and demonstrate the overlapping subproblems that exist.
c) Define a recursive solution to the problem to obtain the optimal result.
d) Demonstrate your recursive solution using a bottom-up approach to computing it
with the following items in the form (pi, wi) with a maximum weight of W = 15:
i1: ($2,1)
• 12: ($5,3)
• 23: ($8,5)
i4 ($11,6)
25 ($12,8)
e) State the optimal result for the given input.
![c) Lion Bytes (W, jin)
if n == 0
return 0;
t = 0₁₁10
for i inw[; ]
if i <= n
+ = + + 1+ Lion Bytes (w, i, n-i)
returnt](https://content.bartleby.com/qna-images/question/c2239705-c051-40af-901a-0ccb2a28fb27/d8c7a5b7-97a9-4d13-98de-d4faf3f82484/jdrs6iv_thumbnail.jpeg)
Transcribed Image Text:c) Lion Bytes (W, jin)
if n == 0
return 0;
t = 0₁₁10
for i inw[; ]
if i <= n
+ = + + 1+ Lion Bytes (w, i, n-i)
returnt
Expert Solution

arrow_forward
Step 1
Here, the problem is a unbounded knapsack problem. We will solve like this problem the classical way.
Step by stepSolved in 2 steps

Knowledge Booster
Similar questions
- Explain, in your own words, what happens in memory when a recursivefunction is used, and what types of disadvantages a recursive function bringswhen compared to a function that uses iteration.arrow_forwardUsing Python Recursion is the concept of a function calling itself until the problem is solved when the Base Case is met. Study Recursion: See slides in Modules, Practice Slides, lab12 and also Recursion is in chapter 9 of the textbook. Some examples of recursion are: compute [ factorial of a number, towers of Hanoi, fractals (as shown in the textbook), and many more]. Example: See slides Page 2 For this assignment we'll use Collatz Cojecture (see Wikipedia). Collatz Conjecture algorithm: Given a number n, first call to the function: f(n): In the function: if n == 1 return 1: if n is even then f(n/2), i.e. call self with the new value. else (n is odd) call self with the new value, f((n*3)+1) and repeat. All numbers eventually end up with 1. The program should test for the base case which is: if n == 1, in which case it returns to the caller with 1. This problem is perfect to demonstrate Recursion.Create a list with random numbers (you can just do this part manually) in the list as 1,…arrow_forwardConsider the following sequence and answer the questions 2, 7, 14, 23, 34, . (1) Develop the recursive solution to identify numbers in the list. (2) Develop the closed-form solution of the recursive solution you made in the previous question.arrow_forward
- Need help with this python recursive basic pathfinding question. I have the layout of the code but I need help filling in the parts that say "pass" and I need the output of the code to match the sample run below. Our goal is to find a path (not the best path, but just any path) from A to Z. You see that the green path is not the shortest but it does let us navigate from start to finish. (The picture below) First, we need to know A and Z, our starting and ending points. We'll pass these into our function. I'm going to use a dictionary to represent this graph. Each node (vertex, circle) will have a name, in this case "A" and "Z" were the names of the nodes, but in the generated maps I'm going to use "Node 1", "Node 2", "Node 3", etc. Here is an example web_map web_map = { 'Node 1': ['Node 3', 'Node 2'], 'Node 2': ['Node 1', 'Node 4'], 'Node 3': ['Node 1'], 'Node 4': ['Node 2'] } Node 1 is connected to 2 and 3 for instance, and then also note that Node 3 is connected back to…arrow_forwardT/F 12. If the Hanoi Towers puzzle was to be created with four towers rather than three with the rules modified accordingly, a recursive answer for a puzzle might be developed where one of the requirements is that any disc has to lie in one of the four towers at any stage in the solution.arrow_forwardwhat is a recursive solution to a problem?arrow_forward
- Discuss the negative aspects of using recursion?arrow_forwardbottom up recursive solution to 1 + 2 + 3 +...+ n please show work step by step (dyanamic programming) on paper/ typedarrow_forwardDifferentiate between Recursion and Iteration and when to use them. (b) Give two (2) examples of problems that can be solved using Recursion.arrow_forward
- There are two important parts to every simple recursive function: the base case, and the recursive call that makes progress towards the base case. Something that can go wrong with recursion when it is used incorrectly is a stack overflow. Explain two different ways that a recursive function could be written incorrectly that could lead to stack overflow. Hint: one has something to do with the base case, and the other with the recursive call. 1. Enter your answer here 2. Enter your answer herearrow_forwardDescribe a recursive approach for computing the prime factors of a number.arrow_forwardTRUE OR FASLE A recursive solution can be implemented within two function one that is recursive and one that is not C PROGRAMMING LANGUAGEarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY

Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON

Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science

Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning

Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning

Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education

Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY