solve2 - CSE2011F06/HR - Solution of #2 1. Answer the...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE2011F06/HR - Solution of #2 1. Answer the following questions about. .. a. No, the iterator of MyArrayList is not fail-fast. To make it so, we need to introduce the attribute modCount to the outer class (to keep track of the number of structural modifications made) and an attribute expectedModCount to the iterator's inner class. Whenever an iterator is instantiated, we keep a snapshot of modCount in expectedModCount . If these two attributes are ever unequal, we throw a concurrent modification exception. The details can be found in the implementation of MyLinkedList which, unlike MyArrayList , does have a fail-fast iterator. b. The add(<AnyType>) method invokes add(int, <AnyType>) , which invokes getNode(int) and addBefore(Node, <AnyType>) . The former is invoked with the index being the size of the list and, hence, it runs in θ(1) as evident from its implementation in Fig. 3.31. The latter runs in θ(1) in all cases (see Fig. 3.28). Hence, the overall running time is θ(1). c. We see that this method invokes
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 2

solve2 - CSE2011F06/HR - Solution of #2 1. Answer the...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online