When Bob wants to send Alice a message M on the Internet, he breaks M into n data packets, numbers the packets consecutively, and injects them into the network. When the packets arrive at Alice’s...
Recent Questions
A useful operation in databases is the natural join. If we view a database as a list of ordered pairs of objects, then the natural join of databases A and B is the list of all ordered triples...
1. Describe an efficient method for maintaining a favorites list L, with the move-tofront heuristic, such that elements that have not been accessed in the most recent n accesses are automatically...
Redo Exercise C-7.51 assuming L is implemented with an array list.Exercise C-7.51There is a simple algorithm, called bubble-sort, for sorting a list L of n comparable elements. This algorithm scans...
1. Describe a scheme for creating list iterators that fail fast, that is, they all become invalid as soon as the underlying list changes.2. There is a simple algorithm, called bubble-sort, for...
1. Design a circular positional list ADT that abstracts a circularly linked list in the same way that the positional list ADT abstracts a doubly linked list.2. Provide an implementation of the...
An array is sparse if most of its entries are null. A list L can be used to implement such an array, A, efficiently. In particular, for each nonnull cell A[i], we can store a pair (i,e) in L, where...
Reimplement the LinkedPositionalList class so that an invalid position is reported in a scenario such as the one described in Exercise R-7.14.Exercise R-7.14 The LinkedPositionalList implementation...
Modify the LinkedPositionalList class to support a method swap(p, q) that causes the underlying nodes referenced by positions p and q to be exchanged for each other. Relink the existing nodes; do...
1. Page 281 describes an array-based representation for implementing the positional list ADT. Give a pseudocode description of the addBefore method for that representation.2. Describe a method for...
1. Modify our LinkedPositionalList implementation to support the Cloneable interface, as described in Section 3.6.2. Describe a nonrecursive method for reversing a positional list represented with a...
Redo the previous problem, but providing an implementation within the class LinkedPositionalList that does not create or destroy any nodes.Exercise C- 7.39Suppose we want to extend the...
Suppose we want to extend the PositionalList abstract data type with a method, moveToFront(p), that moves the element at position p to the front of a list (if not already there), while keeping the...
Explain how any implementation of the PositionalList ADT can be made to support all methods of the List ADT, described in Section 7.1, assuming an implementation is given for the positionAtIndex(i)...
Repeat the previous problem, but use knowledge of the size of the list to traverse from the end of the list that is closest to the desired index.Exercise C-7.36Suppose we want to extend the...
Suppose we want to extend the PositionalList interface to include a method, positionAtIndex(i), that returns the position of the element having index i (or throws an IndexOutOfBoundsException, if...
1. Describe how to implement the queue ADT using two stacks as instance variables, such that all queue operations execute in amortized O(1) time. Give a formal proof of the amortized bound.2....
How might the LinkedPositionalList class be redesigned to detect the error described in Exercise R-7.14.Exercise R-7.14The LinkedPositionalList implementation of Code Fragments 7.9–7.12 does not do...
Consider a variant of Exercise C-7.29, in which an array of capacity N, is resized to capacity precisely that of the number of elements, any time the number of elements in the array goes strictly...
Prove that when using a dynamic array that grows and shrinks as in the previous exercise, the following series of 2n operations takes O(n) time: n insertions at the end of an initially empty list,...
Give a formal proof that any sequence of n push or pop operations (that is, insertions or deletions at the end) on an initially empty dynamic array takes O(n) time, if using the strategy described...
1. Revise the array list implementation given in Section 7.2.1 so that when the actual number of elements, n, in the array goes below N/4, where N is the array capacity, the array shrinks to half...
1. Complete the previous exercise, except using a dynamic array to provide unbounded capacity.2. Modify our ArrayList implementation to support the Cloneable interface, as described in Section...
1. Implement a resetCounts( ) method for the FavoritesList class that resets all elements’ access counts to zero (while leaving the order of the list unchanged).2. Give an array-based list...
1. Suppose that we have made kn total accesses to the elements in a list L of n elements, for some integer k ≥ 1. What are the minimum and maximum number of elements that have been accessed fewer...
1. Demonstrate how to use the java.util.Colletions.reverse method to reverse an array of objects.2. Given the set of element {a,b,c,d,e,f } stored in a list, show the final state of the list,...
1. The java.util.Collection interface includes a method, contains(o), that returns true if the collection contains any object that equals Object o. Implement such a method in the ArrayList class of...
Consider a variant of Exercise C-7.29, in which an array of capacity N is resized to capacity precisely that of the number of elements, any time the number of elements in the array goes strictly...
1. Describe how to implement a method, alternateIterator( ), for a positional list that returns an iterator that reports only those elements having even index in the list.2. Redesign the Progression...
The LinkedPositionalList implementation of Code Fragments 7.9–7.12 does not do any error checking to test if a given position p is actually a member of the relevant list. Give a detailed explanation...
Suppose we want to extend the PositionalList abstract data type with a method, findPosition(e), that returns the first position containing an element equal to e (or null if no such position exists)....
Suppose we want to extend the PositionalList abstract data type with a method, indexOf(p), that returns the current index of the element stored at position p. Show how to implement this method using...
1. Reimplement the ArrayStack class, from Section 6.1.2, using dynamic arrays to support unlimited capacity2. Describe an implementation of the positional list methods addLast and addBefore realized...
The add method for a dynamic array, as described in Code Fragment 7.5, has the following inefficiency. In the case when a resize occurs, the resize operation takes time to copy all the elements from...
Suppose we are maintaining a collection C of elements such that, each time we add a new element to the collection, we copy the contents of C into a new array list of just the right size. What is the...
Consider an implementation of the array list ADT using a dynamic array, but instead of copying the elements into an array of double the size (that is, from N to 2N) when its capacity is reached, we...
Redo the justification of Proposition 7.2 assuming that the the cost of growing the array from size k to size 2k is 3k cyber-dollars. How much should each push operation be charged to make the...
To better model a FIFO queue in which entries may be deleted before reaching the front, design a LinkedPositionalQueue class that supports the complete queue ADT, yet with enqueue returning a...
The java.util.ArrayList includes a method, trimToSize( ), that replaces the underlying array with one whose capacity precisely equals the number of elements currently in the list. Implement such a...
Draw a representation, akin to Example 7.1, of an initially empty list L after performing the following sequence of operations: add(0, 4), add(0, 3), add(0, 2), add(2, 1), add(1, 5), add(1, 6),...
Recent Comments