Question

Recursive backtracking: Suppose I want to burn some songs onto a 650MB CD (some people still...

Recursive backtracking:

Suppose I want to burn some songs onto a 650MB CD (some people still do!) and I have a list of song tracks of various sizes.

I want to fill up as much of my CD as I can. I can use a recursive backtracking strategy to find a subset of the song tracks that optimally fills my CD (that is, with the least space left unfilled). You should recognise this problem as a version of the Knapsack problem.Here is the basic recursive backtracking strategy:

if there are no more songs to consider:

 return solution

else:

 for the next song in the list:
  try not adding it to the CD, use recursion to evaluate the best solution without it
  try adding it to the CD, use recursion to evaluate best solution with it
 return the best of these two results as the best solution from here

(a) What should an input instance for this problem consist of?

(b) Given an input instance, what should be returned as a valid solution for the problem?

(c) Given a valid solution, what is the measure to be used to determine if it is better than some other solution?

(d) What basic strategy can be used to prune the recursion tree?

(e) Using your answers to the previous parts of this question as a basis, write down a recursive back-tracking algorithm that solves the CD-fill problem. You can write the code for your algorithm using normal Python syntax, or you can use pseudocode.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

This problem is simply a variation of Knapsack problem, In this problem we have different songs of different sizes and we need to accomodate as many songs in a constant size knapsack which is CD of size 650MB here.

a. So the input instance for this problem would be the sizes of the songs which needs to be accomodated in the CD.

b. So as we have the different sizes of the songs, thus we need to output the maximum number of songs we can accomodate in the constant size CD.

c. For checking if the given solution is better, we need to find one other solution where number of songs which are getting accomodated in the CD are more than the current found solution.

d. We can save the sub-solutions in order to not calculate the sub-solutions again and again, this basic strategy is also called as memoization, in which we generally remember the solutions to some problem and if the same problem comes again then we can directly use the saved solution which was calculated previously.

e. Following is the code in python programming.

# Here W is the size of CD left to be filled
# w is the list of song size
# n is the number of songs left to be chosen from
def CD-Fille(W , wt, n): 
    # if no song is there or CD size is empty
    if n == 0 or W == 0 : 
        return 0
  
    # If weight of the nth item is more than Knapsack of capacity 
    # W, then this item cannot be included in the optimal solution 
    if (wt[n-1] > W): 
        return knapSack(W , wt , val , n-1) 
  
    # return the maximum of two cases: 
    # (1) nth song included so 1 is added
    # (2) not included 
    else: 
        return max( 1+ CD-Fill(W-wt[n-1] , wt, n-1), 
                   CD-Fill(W , wt, n-1)) 
 

IF you have any problem regarding the understanding of the solution, do let me know in the comment section.
Thanks

Add a comment
Know the answer?
Add Answer to:
Recursive backtracking: Suppose I want to burn some songs onto a 650MB CD (some people still...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a JAVA program to solve a sudoku! Given a partially filled 9×9 2D array ‘grid[9][9]’,...

    Write a JAVA program to solve a sudoku! Given a partially filled 9×9 2D array ‘grid[9][9]’, the goal is to assign digits (from 1 to 9) to the empty cells so that every row, column, and subgrid of size 3×3 contains exactly one instance of the digits from 1 to 9. I have posted 3 input files: sudoku1.txt, sudoku2.txt and sudoku3.txt Problem Analysis & Design - Think about how you will need to solve this problem. You should do an...

  • LANGUAGE IS C++ Lab Ch14 Recursion In this lab, you are provided with startup code which...

    LANGUAGE IS C++ Lab Ch14 Recursion In this lab, you are provided with startup code which has six working functions that use looping (for, while, or do loops) to repeat the same set of statements multiple times. You will create six equivalent functions that use recursion instead of looping. Although looping and recursion can be interchanged, for many problems, recursion is easier and more elegant. Like loops, recursion must ALWAYS contain a condition; otherwise, you have an infinite recursion (or...

  • I really would appreciate some help with this assignment and include comments please as I am...

    I really would appreciate some help with this assignment and include comments please as I am in this for learning. Part I: Maximum increasing subsequence (adapted from Programming Exercise 22.2) Write a program MaxlncreasingSubseq.java that prompts the user to enter a string and displays a maximum length increasing subsequence of characters. Here are four sample runs Enter a string: zebras ers Enter a string: Welcome Welo Enter a string: mmmoooooovwwvee mov Enter a string: abqrstcxyzdefghij abcdefghij You must use dynamic...

  • The Problem A robot is asked to navigate a maze. It is placed at a certain...

    The Problem A robot is asked to navigate a maze. It is placed at a certain position (the starting position) in the maze and is asked to try to reach another position (the goal position). Positions in the maze will either be open or blocked with an obstacle. Positions are identified by (x,y) coordinates. At any given moment, the robot can only move 1 step in one of 4 directions. Valid moves are: ● Go North: (x,y) -> (x,y-1) ●...

  • CMPS 12B Introduction to Data Structures Programming Assignment 2 In this project, you will write...

    can i get some help with this program CMPS 12B Introduction to Data Structures Programming Assignment 2 In this project, you will write a Java program that uses recursion to find all solutions to the n-Queens problem, for 1 Sns 15. (Students who took CMPS 12A from me worked on an iterative, non-recursive approach to this same problem. You can see it at https://classes.soe.ucsc.edu/cmps012a/Spring l8/pa5.pdf.) Begin by reading the Wikipcdia article on the Eight Queens puzzle at: http://en.wikipedia.org/wiki/Eight queens_puzzle In...

  • Hello. I was trying to do the question but i think my direction is wrong. Can you help me to solve it please. a) T...

    Hello. I was trying to do the question but i think my direction is wrong. Can you help me to solve it please. a) Titration of Borax Pipette accurately 10.0 cm of the mixed solution into a 200 or 250 cm conical flask and then add a few drops of methyl red (colour change for this indicator is from red in acid to yellow in basic solution) or screened methyl red indicator. Place this flask on a white, glazed plate...

  • Question 2: Finding the best Scrabble word with Recursion using java Scrabble is a game in...

    Question 2: Finding the best Scrabble word with Recursion using java Scrabble is a game in which players construct words from random letters, building on words already played. Each letter has an associated point value and the aim is to collect more points than your opponent. Please see https: //en.wikipedia.org/wiki/Scrabble for an overview if you are unfamiliar with the game. You will write a program that allows a user to enter 7 letters (representing the letter tiles they hold), plus...

  • What is the role of polymorphism? Question options: Polymorphism allows a programmer to manipulate objects that...

    What is the role of polymorphism? Question options: Polymorphism allows a programmer to manipulate objects that share a set of tasks, even though the tasks are executed in different ways. Polymorphism allows a programmer to use a subclass object in place of a superclass object. Polymorphism allows a subclass to override a superclass method by providing a completely new implementation. Polymorphism allows a subclass to extend a superclass method by performing the superclass task plus some additional work. Assume that...

  • Programming Language: JAVA Construct a program that uses an agent to solve a Sudoku puzzle as...

    Programming Language: JAVA Construct a program that uses an agent to solve a Sudoku puzzle as a Constraint Satisfaction Problem, with the following guidelines: 1. Since 3 x 3 puzzles are too trivial for a computer, your program should use 4 x 4 puzzles (also known as Super Sudoku puzzles; see Figure 2 for an example). 2. The program should read a Sudoku puzzle from a text file. The user should be able to browse the file system to select...

  • Assignment 5 will be way different. It will be more like what you will receive in...

    Assignment 5 will be way different. It will be more like what you will receive in a programming shop. By that I mean that some things are built for you and others you will need to create or finish. P.S. part of your grade will include: Did you add in the required files? Did you rename your project? does your linear searches work? Did you put your code in the correct modules? did you change modules that you weren't supposed...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT