1. Give a description, in pseudocode, for implementing the retainAll method for the set ADT, using only the other fundamental methods of the set.2. If we let n denote the size of set S, and m denote...
Recent Questions
Draw the result after performing the following series of operations on the skip list shown in Figure 10.13: remove(38), put(48, x), put(24, y), remove(55). Use an actual coin flip to generate random...
What is the expected running time of the methods for maintaining a maxima set if we insert n pairs such that each pair has lower cost and performance than one before it? What is contained in the...
1. Describe how a sorted list implemented as a doubly linked list could be used to implement the sorted map ADT.2. Consider the following variant of the findIndex method of the SortedTableMap class,...
Implement the containKey(k) method, as described in Exercise R-10.3, for the SortedTableClass.Exercise R-10.3The use of null values in a map is problematic, as there is then no way to differentiate...
1. Modify our ProbeHashMap to use quadratic probing.2. Explain why a hash table is not suited to implement a sorted map.3. What is the worst-case asymptotic running time for performing n deletions...
1. Our AbstractHashMap class maintains a load factor λ ≤ 0.5. Reimplement that class to allow the user to specify the maximum load, and adjust the concrete subclasses accordingly.2. Give a...
Consider lines 31–33 of Code Fragment 10.8 in our implementation of the class ChainHashMap. We use the difference in the size of a secondary bucket before and after a call to bucket.remove(k) to...
Modify the Pair class from Code Fragment 2.17 on page 92 so that it provides a natural definition for both the equals( ) and hashCode( ) methods.Fragment 2.17
1. Give a pseudocode description of the remove map operation for a skip list.2. Give a description, in pseudocode, for implementing the removeAll method for the set ADT, using only the other...
1. What is the worst-case time for putting n entries in an initially empty hash table, with collisions resolved by chaining? What is the best case?2. Show the result of rehashing the hash table...
Show the result of Exercise R-10.6, assuming collisions are handled by quadratic probing, up to the point where the method fails.Exercise R-10.6Draw the 11-entry hash table that results from using...
1. Draw the 11-entry hash table that results from using the hash function, h(i) = (3i + 5) mod 11, to hash the keys 12, 44, 13, 88, 23, 94, 11, 39, 20, 16, and 5, assuming collisions are handled by...
1. Which of the hash table collision-handling schemes could tolerate a load factor above 1 and which could not?2. What would be a good hash code for a vehicle identification number that is a string...
The use of null values in a map is problematic, as there is then no way to differentiate whether a null value returned by the call get(k) represents the legitimate value of an entry (k,null), or...
1. What is the worst-case running time for inserting n key-value pairs into an initially empty map M that is implemented with the UnsortedTableMap class?2. Reimplement the UnsortedTableMap class...
Let S be a set of n points in the plane with distinct integer x- and y-coordinates. Let T be a complete binary tree storing the points from S at its external nodes, such that the points are ordered...
One of the main applications of priority queues is in operating systems—for scheduling jobs on a CPU. In this project you are to build a program that schedules simulated CPU jobs. Your program...
Write a program that can process a sequence of stock buy and sell orders as described in Exercise C-9.48.Exercise C-9.48An online computer system for trading stocks needs to process orders of the...
What is the result of Exercise R-10.6 when collisions are handled by double hashing using the secondary hash function h′ (k) = 7−(k mod 7)?Exercise R-10.6Draw the 11-entry hash table that results...
1. Develop a Java implementation of an adaptable priority queue that is based on an unsorted list and supports location-aware entries.2. Write an applet or stand-alone graphical program that...
1. Extend a solution to the previous problem so that users are allowed to update the prices for their buy or sell orders that have yet to be processed.2. Implement the in-place heap-sort algorithm....
An online computer system for trading stocks needs to process orders of the form “buy 100 shares at $x each” or “sell 100 shares at $y each.” A buy order for $x can only be processed if there is an...
1. Give an alternate description of the in-place heap-sort algorithm using the standard minimum-oriented priority queue (instead of a maximum-oriented one).2. A group of children want to play a...
1. Describe an in-place version of the selection-sort algorithm for an array that uses only O(1) space for instance variables in addition to the array.2. Assuming the input to the sorting problem is...
1. Implement the binarySearch algorithm (see Section 5.1.3) using a Comparator for an array with elements of generic type E.2. Given a class, MinPriorityQueue, that implements the minimum-oriented...
Write a comparator for nonnegative integers that determines order based on the number of 1’s in each integer’s binary expansion, so that i
1. Explain how the k largest elements from an unordered collection of size n can be found in time O(n+k log n) using a maximum-oriented heap.2. Explain how the k largest elements from an unordered...
Tamarindo Airlines wants to give a first-class upgrade coupon to their top logn frequent flyers, based on the number of miles accumulated, where n is the total number of the airlines’ frequent...
Use the approach of either Exercise C-9.39 or C-9.40 to reimplement the method getFavorites of the FavoritesListMTF class from Section 7.7.2. Make sure that results are generated from largest to...
Suppose two binary trees, T1 and T2, hold entries satisfying the heap-order property (but not necessarily the complete binary tree property). Describe a method for combining T1 and T2 into a binary...
Provide a justification of the time bounds in Table 9.5.Table 9.5
Given a heap H and a key k, give an algorithm to compute all the entries in H having a key less than or equal to k. For example, given the heap of Figure 9.12a and query k = 7, the algorithm should...
We can represent a path from the root to a given node of a binary tree by means of a binary string, where 0 means “go to the left child” and 1 means “go to the right child.” For example, the path...
When using a linked-tree representation for a heap, an alternative method for finding the last node during an insertion in a heap T is to store, in the last node and each leaf node of T, a reference...
Assume that we are using a linked representation of a complete binary tree T, and an extra reference to the last node of that tree. Show how to update the reference to the last node after operations...
1. Reimplement the SortedPriorityQueue using a Java array. Make sure to maintain removeMin’s O(1) performance.2. Give an alternative implementation of the HeapPriorityQueue’s upheap method that uses...
Professor Idle suggests the following solution to the previous problem. Whenever an entry is inserted into the queue, it is assigned a key that is equal to the current size of the queue. Does such a...
1. Describe a sequence of n insertions in a heap that requires Ω(nlogn) time to process.2. Show how to implement the stack ADT using only a priority queue and one additional integer instance...
Give an alternative analysis of bottom-up heap construction by showing the following summation is O(1), for any positive integer h:
Recent Comments