Menu

[Solved] Overview Write Class Sortsearch Utility Class Contains Static Methods Class Contain Three Q37284512

Overview:

  1. Write the class SortSearch which is a utility class thatcontains only static methods. The class will contain three staticmethods, each used for a specialized methodology related to sortingand searching.
  2. Download and use a tester module to ensure that your program iscorrect.
  3. Prepare the assignment for submission and submit it.

Notes:

  • You are not forbidden to use imports, but you will most likelynot need them.
  • There is no restriction on which sort or search algorithm(s)you employ in your solution.
  • If your method modifies the input array as a side effect ratherthan as an intended effect, it is good form to make a copy of thearray instead (this will not be checked, but is a good idea to doanyways).
  • You may include your own helper methods (both public orprivate).

Background:

Most of us are familiar with what sorting and searching means:the former refers to locating a specific element in a list orarray, while the latter refers to putting a list or collection intoorder. In class, we will have discussed various algorithms forsorting and for searching. Knowing these approaches, it is naturalto adapt them to specific problems. For example, when it comes tosearching, we may not want to sort in the natural order (i.e.increasing element values), but some variation instead (reverseorder, or distance from a specific value, or something morecomplicated). When it comes to searching, maybe we do not want tofind the exact match of a key, but instead find an element whichmatches a broader condition. In this lab, we will be implementingseveral variants on the basic idea of searching and sorting.

findFirstDist task:
public static int findFirstDist(int[] array, int v, int d)

(3pts) This is a search method which finds the index ofthe first element in array which lies within a distance d of v.Thus, for example, if d=3 and v=2 then this method would return theindex of the first array element which is either a -1, 0, 1, 2, 3,4, or 5. If no such element is found, then -1 is returnedinstead.

sortDist task:
public static void sortDist(int[] array, int v)

(3pts) Here we implement a sorting task which will takethe input array and place the elements in sorted order. However,sorted order will not mean smallest to largest but from the closestto value v to the farthest from value v. Ties are broken using theorder from the original array.

findKthFromV task:
public static int findKthFromV(int[] array, int k, int v)

(3pts) The goal of this method is to find the kthclosest element to a given value v. If k=1 it would return thevalue of the array element which is closest in value to v. If k=2it would find the second closest, etc. This method is closeslyrelated to sorting: if we knew what order the elements came in,then would we be able to use that to decude the kth element? Aswith the sort method above, ties are broken based on the order theyshow up in the array.

Tip 1: this method returns the value of the element found,not its index.
Tip 2: be aware that an array’s index begins at zero, but theclosest element is the 1st element.

Expert Answer


Answer to Overview: Write the class SortSearch which is a utility class that contains only static methods. The class will contain … . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *