Chapter 4: Problem 33
Write the dynamic programming algorithm for the 0 -1 Knapsack problem.
Chapter 4: Problem 33
Write the dynamic programming algorithm for the 0 -1 Knapsack problem.
All the tools & learning materials you need for study success - in one app.
Get started for freeShow that a binary tree corresponding to an optimal binary prefix code must be full. A full binary tree is a binary tree such that every node is either a leaf or it has two children.
Use a greedy approach to write an algorithm for the Traveling Salesperson problem. Show that your algorithm does not always find a minimumlength tour.
Suppose we assign \(n\) persons to \(n\) jobs. Let \(C_{i j}\) be the cost of assigning the th person to the jth job. Use a greedy approach to write an algorithm that finds an assignment that minimizes the total cost of assigning all \(n\) persons to all \(n\) jobs. Analyze your algorithm and show the results using order notation.
Suppose we minimize the average time to store \(n\) files of lengths \(l_{1}, l_{2}, \dots, l_{n}\) on a tape. If the probability of requesting file \(k\) is given by \(p_{k}\), the expected access time to load these \(n\) files in the order \(k_{1}, k_{2}, \ldots, k_{n}\) is given by the formula \(T_{\text {average}}=C \sum_{f=1}^{n}\left(p_{k_{f}} \sum_{i=1}^{f} l_{k_{i}}\right)\) The constant \(C\) represents parameters such as the speed of the drive and the recording density. a. In what order should a greedy approach store these files to guarantee minimum average access time? b. Write the algorithm that stores the files, analyze your algorithm, and show the results using order notation.
Use a greedy approach to construct an optimal binary search tree by considering the most probable key, Key \(_{k}\), for the root, and constructing the left and right subtrees for \(K e y_{1}, K e y_{2}, \ldots\) Keyk-1 and Keyk+1, Keyk+2,..., Keyn a. Assuming the keys are already sorted, what is the worst-case time complexity of this apporach? Justify your answer. b. Use an example to show that this greedy approach does not always find an optimal binary search tree.
What do you think about this solution?
We value your feedback to improve our textbook solutions.