Question text is in black, answers in blue.
Yes.
My first idea is to make a two-dimensional array of booleans, so that I have an entry for each of the k bits in each of the 2k lines. Then I have to print the array out. Does that make sense?
You could do it that way, but there's no good
reason to have the entire array stored inside your program at once.
If you can figure out the first line of your table, then print it,
then change it to be the second line, then print that, and so forth,
you
get the correct output but you don't need all the storage.
You could even just calculate each bit as you need it, but since
Java prints one line at a time it is probably easier to construct
the line of text as a String
and then print it.
Aren't the lines just the numbers from 0 through 2k - 1 in binary notation, except for the spaces?
Yes. You may be able to use that fact. You are
writing in real Java, so you have access to all kinds of methods in
classes like Integer
if you want to use them. But it
is possible to come up with a correct program that doesn't use
anything fancy.
You say "program", but can I just write a static void method that takes an int k as argument and prints the table for that k as a side effect?
Sure. Or you could have multiple methods if you want.
Part (d) of Problem 1.5.2 is to answer 1.5.2 for the statement in part (d) of Problem 1.5.1. I think you may be looking at Exercise 1.5.2, which is not assigned for the homework because the answer is in the back of the book. Every regular section has both Exercises and Problems -- make sure that you are doing Problems for the homework.
Write a boolean method. A "decision procedure"
for a language always inputs a string and then outputs a boolean,
which is true
if the input string is in the language and
false
if it is not.
The set statement is a valid set identity if it is true for all possible sets and all possible elements. This is true if and only if the corresponding compound proposition is a tautology (true for any truth values of the atomic propositions x ∈ A, x ∈ B, and X ∈ C). You can test whether you have a tautology by the method of truth tables from Section 1.6. You may be able to argue more simply that you have a tautology. If you don't have a tautology, that is because at least one line of the truth table makes the compound proposition false. To answer 1.5.2, you need to find examples of sets A, B, and C and of an element x where this line of the truth table applies.
0 0 0
0 0 1
0 1 0
1 0 0
0 1 1
1 0 1
1 1 0
1 1 1
or in the order you use in your truth tables in Section 1.6:
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
Would I get points taken off for the wrong order?
As you say, the problem doesn't specify an order
so it would be unfair to take points off. Your second order is much
easier to produce, especially if you follow my hint about
Remember that you do need the spaces between the numbers, and that you need
leading zeros so that there are k numbers in each row.
Integer.toBinaryString
, and I prefer it. Among other things it is
the alphabetical order on the rows.
Last modified 2 February 2012