CPSC 327 Data Structures and Algorithms Spring 2024

Homework 19
due Wed 4/3 in class

For the following problem, develop a greedy algorithm algorithm to solve the problem using the 15.5 step greedy algorithm development template. Give each of the steps; don't just give an algorithm — the point here is understanding the process and being able to apply it.

  1. You are creating a playlist for a party. There are n songs that you are considering including; song i has a length li and a popularity pi. Your goal is to create the most popular playlist possible (the playlist's popularity is the sum of the popularities of the songs included), but the playlist can't last any longer than the party does (a total time of L) so you have to decide which songs to include and which to leave out. However, you can include parts of songs; perhaps somewhat unrealistically, the popularity scales so that, for example, half of a song is half as popular as the whole song. Which songs do you include, and how much of each?