Question
Use the definition shown below for the "jumpSearch" method of the SkipSearch class.
Notice that the method is delcared static. Therefore, you do not need to create a new 
instance of the object before the method is called. Simply use "SkipSearch.jumpSearch(...)"
with the appropriate 4 parameter values.

When objects are compared, you should use the "compareTo" method as in the following example.


item.compareTo(array[k])
When an object does not occur in an array, a sequential search for it must examine the entire array. If the array is sorted,


However, not every type of object implements the compareTo method of the Comparable interface.
This is resolved with the use of the syntax " T extends Comparable<? super T>" where "T"
represents the type of objects you want to compare. On the other hand, if you only need to use
one type of data object, then you could just define your data class to implement Comparable instead.

public class SkipSearch
{
    public static <T extends Comparable<? super T>> 
                     boolean jumpSearch( T[] array, int size, T item, int skip ) 
    {
        /*  Searches the first n objects in a sorted array for a given item.
        T      -  data type or class name for the objects in the array.
        array  -  An array of Comparable objects sorted into ascending order.
        size   -  Array size.
        item   -  The item sought.
        skip   -  An integer > 0; The gap between examined items.
        returns  true if the item was found, or false if not. */


        // Insert your code here. Also define the main test class in a separate Java file.

    }
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

public class SkipSearch // you have to save your file with this name only

{

   public static <T extends Comparable<? super T>>

   boolean jumpSearch( T[] array, int size, T item, int skip )            // function used for searching

   {

      for(int i=0; i<size; i=i+skip) {                          // loop for comparing each value in array

           if(array[i].compareTo(item) == 0)                     // if if finds the value , it returns it

               return true;

       }

    

       return false;

   }

}

Add a comment
Know the answer?
Add Answer to:
Use the definition shown below for the "jumpSearch" method of the SkipSearch class. Notice that t...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Can someone help me with the main class of my code. Here is the assignment notes....

    Can someone help me with the main class of my code. Here is the assignment notes. Implement project assignment �1� at the end of chapter 18 on page 545 in the textbook. Use the definition shown below for the "jumpSearch" method of the SkipSearch class. Notice that the method is delcared static. Therefore, you do not need to create a new instance of the object before the method is called. Simply use "SkipSearch.jumpSearch(...)" with the appropriate 4 parameter values. When...

  • Program with generic merge sort and binary search method help. The programming language I'm using is...

    Program with generic merge sort and binary search method help. The programming language I'm using is Java. This program should show understanding generic merge sort methods and generic binary search methods in java. The execution should include at least 5 found items including one from the first three items in the sorted array and one from the last three items in the sorted array as well as at least two items not found Create a generic merge sort method that...

  • Implement the classes in the following class diagram. The Book class implements the Comparable interface. Use impl...

    Implement the classes in the following class diagram. The Book class implements the Comparable interface. Use implements Comparable<Book> in the class definition. Now, all book objects are instances of the java.lang.Comparable interface. Write a test program that creates an array of ten books. 1. Use Arrays.sort( Book[]l books) from the java.util package to sort the array. The order of objects in the array is determined using compareTo...) method. 2. Write a method that returns the most expensive book in the...

  • Due in25 minutes,Java8 programming linkedlist node Given the following definition for a Node class: public class...

    Due in25 minutes,Java8 programming linkedlist node Given the following definition for a Node class: public class Node<T extends Comparable<T>>{ public T val; public Node<T> prev; public Node<T> next; } Create an add method for a Sorted Linked Set. The collection is stored as a linked list, however has a few extra properties. First, as it is a Set, values stored in the list are distinct. Second, the list is sorted (so if 4, 2, 3, 1 were added, they would...

  • The file Sorting.java contains the Sorting class from Listing 9.9 in the text. This class implements...

    The file Sorting.java contains the Sorting class from Listing 9.9 in the text. This class implements both the selection sort and the insertion sort algorithms for sorting any array of Comparable objects in ascending order. In this exercise, you will use the Sorting class to sort several different types of objects. 1. The file Numbers.java reads in an array of integers, invokes the selection sort algorithm to sort them, and then prints the sorted array. Save Sorting.java and Numbers.java to...

  • Modify the sorts (selection sort, insertion sort, bubble sort, quick sort, and merge sort) by adding code to each to tally the total number of comparisons and total execution time of each algorithm. E...

    Modify the sorts (selection sort, insertion sort, bubble sort, quick sort, and merge sort) by adding code to each to tally the total number of comparisons and total execution time of each algorithm. Execute the sort algorithms against the same list, recording information for the total number of comparisons and total execution time for each algorithm. Try several different lists, including at least one that is already in sorted order. ---------------------------------------------------------------------------------------------------------------- /** * Sorting demonstrates sorting and searching on an...

  • 1. Submit a Screenshot with a visible operating system data/time with the primary code in your...

    1. Submit a Screenshot with a visible operating system data/time with the primary code in your IDE and the compilation results. 2. Submit the code required by My Programming Lab. Chapter 16 MyProgrammingLab Exercise 20776 Assume the existence of a Widget class that implements the Comparable interface and thus has a compareTo method that accepts an Objectparameter and returns an int. Write an efficient static method, getWidgetMatch, that has two parameters. The first parameter is a reference to a Widget...

  • ONLY NEED THE DRIVER CLASS PLEASE!!! Domain & Comparator Classes: 0.) Design a hierarchy of classes,...

    ONLY NEED THE DRIVER CLASS PLEASE!!! Domain & Comparator Classes: 0.) Design a hierarchy of classes, where the Media superclass has the artistName and the mediaName as the common attributes. Create a subclass called CDMedia that has the additional arrayList of String objects containing the songs per album. Create another subclass called DVDMedia that has the additional year the movie came out, and an arrayList of co-stars for the movie. 1.) The superclass Media will implement Comparable, and will define...

  • I need to do a tree sort method but the treesortMethod is not working /****Binarytree class****\...

    I need to do a tree sort method but the treesortMethod is not working /****Binarytree class****\ package Tree; public class BinaryTree { private TreeNode root; // head of the list    //constructor - create an empty binary tree public BinaryTree() { root = null;    }    //isEmpty() - return true if tree is empty, false otherwise public boolean isEmpty() { return (root == null); }    //deleteTree() - remove all items from tree public void deleteList() { root =...

  • Protocol Exercise 1- Adopt Protocols: CustomStringConvertible, Equatable, and Comparable Create a Human class with two properties:...

    Protocol Exercise 1- Adopt Protocols: CustomStringConvertible, Equatable, and Comparable Create a Human class with two properties: name of type String and age of type Int. You’ll need to create a memberwise initializer for the class. Initialize two Human instances. Make the Human class adopt the CustomStringConvertible. Print both of your previously initialized Human objects. Make the Human class adopt the Equatable protocol. Two instances of Human should be considered equal if their names and ages are identical to one another....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT