22C:21: Computer Science II: Data Structures

Quiz 1: September 3, 2004


1. Consider the following piece of code.
		Vector x(5);
		x.add("4");
		x.add("3");
		x.add("2");
		x.add("5");
		x.add("3");
		x.add(x.remove(1));
		x.add(x.remove("2"));
		x.add("10");

Draw a picture of the Vector x after the above piece of code is executed showing the contents of the Vector clearly. Also, write down the capacity and the size of the Vector.


Answer: The Vector is

	4  5  3  3  2  10  NULL  NULL  NULL  NULL
The capacity is 10 and the size is 6.

2. Assuming that capacityIncrement is set to 0, is it possible for the capacity of a Vector to be larger than 2 times its size after the first time the Vector becomes full? (Yes or No). Justify your answer in one sentence.


Answer: Yes. There are at two ways in which this can happen. Either of these would be considered correct.