Need help making a java file that combines both linearSearch and binarySearch
•Both search methods must use the Comparable<T> interface and the compareTo() method.
•Your program must be able to handle different data types, i.e., use generics.
•For binarySearch, if you decide to use a midpoint computation formula that is different from
the textbook, explain that formula briefly as a comment within your code.
//code from textbook
//linearSearch
public static <T>
boolean linearSearch(T[] data, int min, int max, T target) {
int index = min;
boolean found = false;
while (!found && index <= max) {
found = data [index].equals(target);
index++;
}
return found;
}
//binarySearch
public static <T extends Comparable<T>>
boolean binarySearch(T[] data, int min, int max, T target) {
boolean found = false;
int midpoint = (min + max)/2;
if (data[midpoint].compareTo(target)==0)
found = true;
else if(data[midpoint].compareTo(target)>0) {
if(min<=midpoint-1)
found = binarySearch(data, min, midpoint-1, target);
}
else if (midpoint+1<=max)
found=binarySearch(data, midpoint+1, max, target);
return found;
}
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps
- Write the definition of the class linkedQueueType, which is derived from the class unorderedLinkedList, as explained in this chapter. Also, write a program to test various operations of this class. exercice317 from malik book (eTextbook: C++ Programming: Program Design Including Data Structures)arrow_forwardDesign and implement a service that simulates PHP loops. Each of the three loop variants should be encapsulated in an object. The service can be controlled via a parameter and execute three different simulations. The result is returned as JSON. The input is an array consisting of the letters $characters = [A-Z]. -The For loop should store all even letters in an array.-The Foreach loop simulation is to create a backward sorted array by For loop, i.e. [Z-A] .-The While loop should write all characters into an array until the desired character is found. Interface:-GET Parameter String: loopType ( possible values: REVERSE, EVEN, UNTIL )-GET parameter String: until (up to which character) Output:JSON Object: {loopName: <string>, result: <array> }arrow_forwardNeed help with this Java review If you can also send a screenshot will be helpful to understan Objective: The purpose of this lab exercise is to create a Singly Linked List data structure . Please note that the underlying implementation should follow with the descriptions listed below. Instructions : Create the following Linked List Data Structure in your single package and use "for loops" for your repetitive tasks. Task Check List ONLY "for" loops should be used within the data structure class. Names of identifiers MUST match the names listed in the description below. Deductions otherwise. Description The internal structure of this Linked List is a singly linked Node data structure and should have at a minimum the following specifications: data fields: The data fields to declare are private and you will keep track of the size of the list with the variable size and the start of the list with the reference variable data. first is a reference variable for the first Node in…arrow_forward
- Write a program to check whether a given word is a palindrome by using pointers A palindrome is a word that is the same when spelled from the front and from the back. For example, Kayak, Level, Racecar, Radar, Rotator Create 2 char arrays and 2 corresponding pointers to the arrays Initialize array1 to the word Copy array1 backwards to array2 Compare array1 and array2, if they are the same, the word is a palindrome Modify the pseudocode below to produce the sample output. char word[5]= "kayak"; char reverseWord[S); char *f = word; char *b = reverseWord; for () { *(b_from_start) = *(f_from_end); Copy word to reverseWord but starting from the back for() { Compare word and reverseWord if same palindrome; Sample: word word_reverse word word_reverse k a a Palindrome? Yes Palindrome? Noarrow_forwardAssume that you need to organize the data of books. Existing books should be rearranged so that only one side of the shelf is empty, or new volumes should be placed there. In this case, what would be the best data structure? Make it possible to dynamically implement the process of adding books to the bookcase. Furthermore, what is the circumstance where fresh data need to be entered into a data structure, but there is no room?arrow_forwardIn java, the Arrays class contains a static binarySearch() method that returns …… if element is found. false true (-k–1) where k is the position before which the element should be inserted The index of the elementarrow_forward
- What is the difference between void and NULL pointers .Give suitable examples in support of your answer .arrow_forwardWrite the question also in c ++ language. Question 2.An array containing the given n-element integers and the sum of the consecutive elements in the amray with the integer k Find how many of them are divisible without remainder to the given integer k. • The array contains n elements ( array = [array (0], array (1]..., array [n-1]] ). •k is a positive integer • Sum of consecutive elements for any ( first , next ) pair array [first) + array [next) if o firstarrow_forwardWrite a Menu driven Program which includes these operations like insertion, deletion, and fetching all the elements from an array? (write the program in c++ language, here menu-driven means you can use switch cases)arrow_forwardIn C++, write a program that reads in an array of type int. You may assume that there are fewer than 20 entries in the array. The output must be a two-column list. The first column is a list of the distinct array elements and the second column is the count of the number of occurences of each element.arrow_forwardCalculate a transpose of a matrix. Using C++ language. Output file should be attached to it.arrow_forwardIn this task you will work with the linked list of digits we have created in the lessons up to this point. As before you are provided with some code that you should not modify: A structure definition for the storage of each digit's information. A main() function to test your code. The functions createDigit(), append(), printNumber(), freeNumber(), readNumber() and divisibleByThree() (although you may not need to use all of these). Your task is to write a new function changeThrees() which takes as input a pointer that holds the address of the start of a linked list of digits. Your function should change all of those digits in this linked list that equal 3 to the digit 9, and count how many replacements were made. The function should return this number of replacements. Provided codearrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY