LMU ☀️ CMSI 2130
ALGORITHMS
HOMEWORK #4

Instructions

Turn in all solutions (including those requiring code) neatly typeset on 8.5" × 11" paper, with a staple in the upper left corner.

Store your files in a private GitHub repository named <yourgithubname>/cmsi282. At the top level of this repository create a folder called homework4 in which your files will be placed. During grading, I may clone your repository and run my own test suite on your code, so don’t forget to give me access to your repo. My github name is rtoal. I will be looking for your code in the branch master, of course.

I encourage you to work in pairs. Please submit only one solution set for your team.

This is due at the beginning of class on Tuesday, April 26, 2016.

Readings, Videos, and Practice

Just read, watch, and do. You do not have to take notes or write reports on them; however, don’t cheat yourself by skipping them. These independent learning units must be done individually, but please feel free to discuss these items with your partner, your friends, or even with the rest of the class on the Discussion Boards.

The Problems

  1. Dasgupta problem 3.8, implemented in Python, Java, or other popular language, as a function producing an array of strings such as "E4" (empty the 4-pint container), "F10" (fill the 10-pint container), and "T74" (transfer from the 7-pint container to the 4-pint container until either the source is empty or the target is full).
  2. Dasgupta problem 4.1.
  3. Dasgupta problem 4.2.
  4. Dasgupta Problem 4.18.
  5. Write a script to compute a Minimum Spanning Tree using Prim's Algorithm. The input should be a string representation of a graph according to the following example (you should be able to infer what it means):
      A,B,3|B,C,10|C,A,4|D,E,2|E,A,6
    
    The output should be a string describing the the minimum spanning tree in the same format. Define and throw a UnconnectedGraphException when necessary.
  6. Write a function in Python or Julia or JavaScript or Java (or...) that uses dynamic programming to determine whether a list of positive integers has a subset of elements that sums to a given value.
  7. Combine Dasgupta problems 6.17, 6.18, and 6.19 into a class called Changer. A changer object is initialized with a set of positive integers representing denominations. Provide the methods:
    • can_make_change_for(amount)
    • can_make_change_using_each_coin_once(amount)
    • can_make_change_with_limited_coins(amount, max_coins)

    You must use dynamic programming.