CMPSCI 250: Introduction to Computation

David Mix Barrington

Fall, 2007

Homework #5 Questions and Answers

Question 5.2, 10 November 2007

In your code for Problem 8.2.4, you create a new two-dimensional array with the statement entry = new natural[rows, columns]. Shouldn't this be new natural[rows][columns]?

You seem to be right -- I was sure that Java gave you this alternate way of creating arrays but I can't find a reference to it so it probably doesn't exist.

Question 5.1, 10 November 2007

In 8.2.5, I would like to have a method that will give me a "neutral element" of a Semiring, but you said only that a class implementing Semiring has to support plus and times. Can I have a getNeutralElement method?

Yes, this is a reasonable thing to ask because a semiring has to have "one" and "zero" elements, and so a Semiring ought to give you access to these elements. You can use any reasonable syntax for this, but my suggestion is that the Semiring interface has to include a constructor that takes an int argument. If you call it with the int "0" as parameter you get an object that is the zero element of the semiring, and if you call it with "1" you get the one element.

Last modified 12 November 2007