CMPSCI 250: Introduction to Computation

David Mix Barrington

Fall, 2004

Question and Answers on HW#1

Due on paper in class, Friday 17 September 2004

Questions are in black, answers in blue

Question #6, 15 Sept 2004

In Problem 1.4.3, aren't you asking the same question twice about simulating NOT with NAND? Or am I missing something.

No, you're right, the last question is answered by the earlier question.

Question #5, 14 Sept 2004

My question regards comparing characters. You had mentioned that "==" cannot be used to compare Strings in Java, that instead ".equals" must be used. Is this also true with characters?

No, characters are a primitive type like ints, floats, or booleans. If ch1 and ch2 are character variables, then "ch1 == ch2" will be true if and only if the two variables have the same value.

Question #4, 13 Sept 2004

Do you mind if the homework we turn in is typed as opposed to handwritten?

No, that's fine, actually I prefer it to be typed. What I said is that I want it on paper as opposed to by email, to save the TA the problem of printing it out and so forth. If you can only submit by email for some good reason, like you're stuck out of town on the day of class, contact Harish directly with as much advance warning as possible.

Question #3, 13 Sept 2004

In 1.1.2, I don't see how to prove that "1" is in the set R. Isn't R defined so everything in R is a set? But "1" isn't a set, is it?

You're right, I made a mistake. Just explain why the other two sets are members of R. Sorry.

Question #2, 13 Sept 2004

In 1.2.7 (a), what about strings that have no third letter?

They are not in the language. I meant to say "whose third letter exists and is b". Sorry.

Question #1, 12 Sept 2004

I don't really understand problem 1.2.7 -- can you explain it?

Usually it helps to ask a more specific question, but here goes.

To write "a decision procedure for a language" means to write a static method that takes a String as input and returns a boolean. If the String is in the language, the method should return "true" and if it's not the method should return "false". Each of (a) through (d) is a language, which means a set of strings, or in this case Strings because we're using real Java. So you should write four static methods.

What about the one with palindromes? I can't make it with just one String, I can make it with two.

If you need to create another String variable in your method that's fine, although it's possible to solve the problem without doing this. Remember that if you want to test whether two Strings are equal in real Java you must use the equals methold rather than the == operator because Strings are objects.

I hope it's clear what a palindrome is. The word ""hannah" is a palindrome but "abracadabra" is not because "abracadabra" spelled backwards is "arbadacarba", not "abracadabra".

Last modified 15 September 2004