E 1.
Given an unsorted list of values, what is the time-complexity to find the th smallest value in the worst case? What would be the complexity if the sequence were sorted?
Chapter ExercisesExercisesE 1.
Given an unsorted list of values, what is the time-complexity to find the th smallest value in the worst case? What would be the complexity if the sequence were sorted?E 2.
What is the for the findSortedPosition function in the worst case?E 3.
Consider the new implementation of the Set class using a sorted list with the binary search.
E 4.
Determine the worst case time complexity for each method of the Map ADT implemented in Section 2.8.E 5.
Modify the binary search algorithm to find the position of the first occurrence of a value that can occur multiple times in the ordered list. Verify your algorithm is still .E 6.
Design and implement a function to find all negative values within a given list. Your function should return a new list containing the negative values. When does the worst case occur and what is the run time for that case?E 7.
In this chapter, we used a modified version of the mergeSortedLists function to develop a linear time union operation for our Set ADT implemented using a sorted list. Use a similar approach to implement new linear time versions of the isSubsetOf , intersect , and difference methods.E 8.
Given the following list of keys (80, 7, 24, 16, 43, 91, 35, 2, 19, 72), show the contents of the array after each iteration of the outer loop for the indicated algorithm when sorting in ascending order.
E 9.
Given the following list of keys (3, 18, 29, 32, 39, 44, 67, 75), show the contents of the array after each iteration of the outer loop for the
E 10.
Evaluate the insertion sort algorithm to determine the best case and the worst case time complexities.Programming ProjectsP 1.
Implement the Bag ADT from Chapter 2 to use a sorted list and the binary search algorithm. Evaluate the time complexities for each of the operations.P 2.
Implement a new version of the Map ADT from Section 2.7 to use a sorted list and the binary search algorithm.P 3.
The implementation of the Sparse Matrix ADT from Chapter 5 can be improved by storing the MatrixElement objects in a sorted list and using the binary search to locate a specific element. The matrix elements can be sorted based on the row and column indices using an index function similar to that used with a 2-D array stored in a MultiArray. Implement a new version of the Sparse Matrix ADT using a sorted list and the binary search to locate elements.P 4.
Implement a new version of the Sparse Life Grid ADT from Chapter 4 to use a sorted list and the binary search to locate the occupied cells.P 5.
A colormap is a lookup table or color palette containing a limited set of colors. Early color graphics cards could only display up to 256 unique colors at one time. Colormaps were used to specify which 256 colors should be used to display color images on such a device. Software applications were responsible for mapping each color in the image that was to be displayed to a color in the limited color set specified by the colormap. We can define a Colormap ADT for storing a limited set of colors and for use in mapping one of the 16.7+ million colors possible in the discrete RGB color space to a color in the colormap. Given the description below of various operations, implement the Colormap ADT using a 1-D array structure.
P 6.
Evaluate the map method of your implementation of the Colormap ADT from the previous question to determine the worst case time-complexity.P 7.
Colormaps are used in color quantization, which is the process of reducing the number of colors in an image while trying to maintain the original appearance as much as possible. Part of the process recolors an original image using a reduced set of colors specified in a colormap.
|