Write and implement a recursive version of the sequential search algorithm. Test the algorithm with an array that have ten integer values, user can enter the values or assigned the values to the array in the main method. The search key should be a value in the array or not in the array. JAVA!!!
public class LinearSearch {
public static void main(String[] args) {
int arr[]=
{10,24,12,5,26,33,45,21};
int key=21;
int index=linear_search_rec(arr,
arr.length-1, key);
if(index==-1) {
System.out.println(key+" does not exist in array");
}
else {
System.out.println(key+" found at index "+index);
}
key=29;
index=linear_search_rec(arr,
arr.length-1, key);
if(index==-1) {
System.out.println(key+" does not exist in array");
}
else {
System.out.println(key+" found at index "+index);
}
}
public static int linear_search_rec(int arr[], int n
,int key){
if(n<0) { // Base case - not
found
return -1;
}
if(arr[n]==key) { // Base case -
found
return n;
}
// Recursive case
return linear_search_rec(arr, n-1,
key);
}
}
Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me
Write and implement a recursive version of the sequential search algorithm. Test the algorithm with an...
a. You need write a sequential search algorithm that is recursive format. b. Write a binary search algorithm that is recursive, then write the program to implement it. C++
(Recursive Binary Search) Write a recursive method recursiveBinarySearch to perform a binary search of an array. The method should receive the search key, starting index and ending index as arguments. If the search key is found, return its index in the array. If the search key is not found, return –1. (NOTE: Complete the recursiveBinarySearch method in the BinaryArray class). java
2) Write a recursive procedure in pseudocode to implement the binary search algorithm. 3) Explain, how the binary search algorithm can be modified, or used, to insert, a new integer element x, into a sorted list of n intgers.
Sequential Search Algorithm Python Programming Objectives ---------- * sequential search - design, analyze, implement, test, time * continue practicing previously learned skills: algorithm analysis, graphing with theoretical prediction curves Implementation -------------- Write a function named sequential_search. It must have two parameters, a list to search and a value to search for. It must return either the index of the value within the list or -1 if the value is not found in the list. Your search function should NOT print...
implement and test several recursive methods below. Test all these in the same program. Keep adding methods and testing until all are working.(java) 1.A recursive method to find the sum of all elements of an integer array. The method should have 2 parameters. The array and where to start in the array. Example of initial call: int sum = sumOfValues(array, 0); 2.A recursive method to find the largest element in an integer array. The method should have 2 parameters as...
Just Q3 and Q4 Q1] Write a C function to implement the binary search algorithm over an array of integer numbers and size n. The function should return the index of the search key if the search key exists and return - 1 if the search key doesn't exist. [10 Points] Q2] Write a C function to implement the selection sort algorithm, to sort an array of float values and size n. The function should sort the array in ascending...
Using Java programming language Your assignment is to implement a recursive reverse sorting algorithm. It should meet the following requirements: 1. The program shall graphically prompt the user for a file. 2. The program shall read the selected file which will contain 1 integer per line. 3. The program shall sort the values it reads from the file from largest to smallest. 4. The program shall write the values to an output file from largest to smallest in the same...
in JAVA please thanks. (need answer in a few hours !!) Exercise #1: Design and implement a program (name it LinearBinarySearch) to implement and test the linear and binary search algorithm discussed in the lecture slides. Define method LinearSearch() to implement linear search of an array of integers. Modify the algorithm implementation to count number of comparisons it takes to find a target value (if exist) in the array. Define method BinarySearch() to implement binary search of an array of...
(a) Write a program in Java to implement a recursive search function int terSearch(int A[], int l, int r, int x) that returns the location of x in a given sorted array of n integers A if x is present, otherwise -1. The terSearch search function, unlike the binary search, must consider two dividing points int d1 = l + (r - l)/3 int d2 = d1 + (r - l)/3 For the first call of your recursive search function...
6 (10 points Remember the recursive Searching algorithm Binary Search. Write a recursive method to search for a target character in the array and return the index location if found or -1 if it is not found. 7 a5 points 17 points cach) Write the code to create a GUI based class Temperature Converter which inherits from JFrame and implements the ActionListerner interface. public static int binary Search(char target, char( theValues, int firstIndex, int lastindex) Example: Clicked "F to C"...