next up previous
Next: About this document ... Up: Solutions to Quiz/Homework Assignment Previous: Base case: n=1

Induction step

We assume that the property is true for some n, and show that it is true for n+1. We select two sets of n dogs A and B such that all of the n+1 dogs occurs in at least one of the sets A or B, And there is one dog that appears in both sets (call this dog ``Rover''). Since A and B are of size n, we know from the Induction Hypothesis that the dogs in each set are the same color. Moreover, since Rover is in both sets, both sets must be the same color. So, the property holds for n+1 dogs. QED.

1.
The base case does not cover sets with no dogs (n=0), so we can't conclude that all dogs are the same color for any number of dogs.
2.
We did not mention what happens for n>1, so we have not proven the property for any number of dogs.
3.
The given Induction Step does not work when n=1, so the property does not hold for larger n.
4.
None of the above.

A number of people selected choice (b). The proof doesn't need to explicitly mention what happens for n>1, because the induction step, in combination with the base case, takes care of that. So, implicitly, this proof did mention n>1. It just had flawed reasoning.

The flaw is that the induction step does not work when n=1. Consider what would happen with the set with n+1=2 dogs when n=1. According to the induction step, there is a dog, Rover, who is in both sets. With n=1, the induction step uses sets of 1 dog each, for sets A and B.

If Rover is in both sets, then there's only one dog total (same dog in both sets). If the two sets have different dogs, then Rover doesn't have a place.

So, it's choice (c).

In C, strings are implemented as arrays. They could be implemented using linked lists, specifically a linked list of characters. In the string ``Data Structures are supercool'', the head of the list would be the letter 'D', the next node would be 'a', the next node would be 't', etc.

We could use a singly linked list or a doubly linked list. For which of the following operations, would you want to use a doubly-linked list (assuming the program performed this operation frequently)? Assume that only big-O time is significant.

1.
Find character (e.g., does some string contain the letter 'A'?)
2.
Count length of string (e.g., given ``Data'', the length is 4)
3.
Reverse string (e.g., given ``Data'', output ``ataD'')
4.
Find previous (i.e., given a pointer to a character, find the previous character)
5.
Concatenate strings (e.g., given ``Data'' and ``Structures'', output ``DataStructures'')

note: To get full credit on an answer like this in the future, you'll need to show why the other choices aren't correct. That is, you have to demonstrate that you understand not only why Find previous is difficult for singly linked lists, but also why all of the other choices are just as easy.


next up previous
Next: About this document ... Up: Solutions to Quiz/Homework Assignment Previous: Base case: n=1

2000-01-17