Question text is in black, answers in blue.
That's because I made a mistake -- I meant to assign 9.1.1 and 9.1.5 -- the assignment page is now corrected.
You would need at least four edges if the graph had to be connected (that is, if it had to have a path from every vertex to every other vertex), but it doesn't. A graph doesn't have to have any edges at all, though it has to have at least one vertex.
char charAt (String w, int i) {
char[] a = w.toCharArray();
if (i == 0) return a[0];
else {
String x = "";
for (int n=1; n < a.length; n++)
x += a[n];
return charAt(x, i-1);}}
Your code looks correct, and it does use
recursion, so I'm reproducing it as a useful hint. It's not a
correct
answer for 4.7.5, though, for two reasons: (1) it's in real Java and
I
asked you for pseudo-Java, and (2) it simulates the methods
That said, it's a very smart idea to use your knowledge of real
Java to design a pseudo-Java method in just this way, by simulating
the
basic pseudo-Java operations in real Java, changing data types as
necessary to do that.
To get a correct answer, I'd suggest rewriting your method so
that it recurses on all but the last character of the string,
instead of all but the first as you do here. Then you can translate
into a
pseudo-Java method, taking a first
and allButFirst
and pseudo-Java
strings are based on last
and allButLast
.
string
and a
natural
as arguments and calling the last
and
allButLast
methods.
Question 4.4, posted 3 November 2010: Problem 9.1.5 asks us to prove a theorem about the max and min possible number of leaves in "a rooted tree of depth d and degree k". What does "degree" mean for a tree?
The degree of a graph is the maximum number of
neighbors of any node -- it should be defined again in this chapter,
because you've skipped Chapter 8 where it was defined. For a rooted
tree, what I mean by "degree" is the "branching factor", which is the
maximum number of children for any node. That is, in a "rooted tree
of degree k", every node has a number of children in the range from 0
through k.
Note, by the way, that for the rooted tree to have "depth d", there
must be a d-edge (simple) path from the root to a leaf, and
there
cannot be any longer (simple) path from the root to a leaf.
Question 4.5, posted 7 November 2010: In 9.1.5, suppose I have a rooted tree that has just one node. I know that this tree has depth zero, but how many leaves does it have? Can the root also be a leaf?
Yes, the root of this tree is a node with no children, so it is a leaf as well as the root and this tree has exactly one leaf. You are correct that the depth is zero, because there is a path of length zero (a path with zero edges in it) from the root to a leaf.
Question 4.6, posted 7 November 2010: I'm working on problem 4.3.4 and it says to prove the problem by induction but it seems to be simpler than that. It wants me to show that there exists a polynomial f(x,y) such that xn - yn = (x - y)f(x,y). But isn't (xn - yn)/(x - y) such a polynomial? How would I use induction to prove this?
That expression, (xn - yn)/(x - y), is not a polynomial! Polynomials are made by adding, subtracting, and multiplying numbers and variable, not dividing them. (Division gives you a "rational function".) What you need to do is to find an ordinary polynomial that meets this condition. Start with n = 0, n = 1, and n = 2, and continue until you find a pattern in fn that you can prove by induction. (You can divide one polynomial by another by essentially using long division -- if you wind up with no remainder then you have found a polynomial that is the quotient. For example, with n = 2 you should already know that x = y goes into x2 - y2 with no remainder. What about x3 - y3?)
Question 4.7, posted 8 November 2010: I have a sequence of numbers for 4.11.2, the cheese problem, that I think is right. But I'd like to know that it is right before I start my induction proof.
I won't tell you whether it's right, but with an integer sequence you can often find out things by typing it into the On-Line Encyclopedia of Integer Sequences.
Question 4.8, posted 8 November 2010: I don't think Problem 9.6.3 is stated correctly. Suppose I have an undirected graph with five nodes a, b, c, d, and e connected in a cycle. When I do a BFS from a, it gets children b and e, then b gets child c and e gets child d. The one non-tree edge goes from c to d, who are "first cousins", not siblings. Yet this graph is certainly not bipartite.
You are right, and I have corrected the question. Instead of "siblings" it should say "nodes at the same depth".
Question 4.9, posted 8 November 2010: Can you say more about what you mean by the hint for 4.11.1?
Sure. You're trying to show that the 3 by n rectangle can be tiled if n is even and cannot by tiled if n is odd. The even case is an easy induction on even numbers. For the odd case, it's obvious that P(1) ("the 3 by 1 rectangle cannot be tiled") is true, but your induction of P(n) → P(n+2) is not as obvious. My suggestion is to prove the contrapositive ¬P(n+2) → ¬P(n) instead. Assume that you have a tiling of the 3 by n+2 rectangle. Argue that this tiling must include a tiling of the 3 by n rectangle. Then if the 3 by n+2 tiling exists, the 3 by n must exist. Therefore if the 3 by n does not exist, the 3 by n+2 also does not exist.
Last modified 8 November 2010