Question
We have been asked to construct a program that handles lists of strings, integers, library books, and anything else our client can think of. The
We have been asked to construct a program that handles lists of strings, integers, library books, and anything else our client can think of. The client requires all of the usual operations for a list, such as the ability to add items, remove items, search for items, and get items (in sorted order). Because the client expects that searching for items will be the most common operation for these lists, we must make our search routine as efficient as possible. Further, we have been informed that the lists may not contain duplicates (ie. it is a set). At first, we were a little concerned about taking on such a job, since we have yet to learn any algorithms for sorting lists (much less, super efficient sorting algorithms). However, we know that all such lists will begin as empty lists which are already in sorted order, and we can simply insert items in the correct order to ensure that the lists remain sorted. The data in BinarySearchSet must be backed by a basic array (do not use a Java List). Further more, it is not acceptable for the array to run out of space for new items, nor is it acceptable to create a gigantic array. Start with a modestly-size array and increase the capacity as needed. The contains and add methods must take advantage of the list being sorted and implement a binary search to determine if an item is in the array and to find the correct position in which to insert a new item, respectively. You may not invoke Java's Arrays.binarySearch routine. Do not invoke Java's Arrays.sort routine. (Recall that sorting the list is not necessary.)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started