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++
#include<iostream>
using namespace std;
int binarySearch(int arr[], int l, int r, int x)
{
if (r >= l) {
int mid = l + (r - l) / 2;
// If the element is present at the middle
// itself
if (arr[mid] == x)
return mid;
// If element is smaller than mid, than search left side else right
side
if (arr[mid] > x)
return binarySearch(arr, l, mid - 1, x);
return binarySearch(arr, mid + 1, r, x);
}
//-1 if does not exist
return -1;
}
int binary_search_rec(int *p,int n,int x){
return binarySearch(p,0,n-1,x);
}
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);
}
int main()
{
int arr[] = {10,20,30,55,67,88,98,110,150,170};
int size = 10;
int x=67;
int result = binary_search_rec(arr,size, x);
(result == -1) ? cout << "Element "
: cout << "Element is present at index " <<
result;
cout<<endl<<endl;
result = linear_search_rec(arr, size - 1, x);
(result == -1) ? cout << "Element is not present in
array"
: cout << "Element is present at index " <<
result;
return 0;
}

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
a. You need write a sequential search algorithm that is recursive format. b. Write a binary...
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!!!
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.
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"...
Language = c++ Write a program to find the number of comparisons using the binary search and sequential search algorithms as follows: o Suppose list is an array of 1000 elements. o Use a random number generator to fill the list. o Use the function insertOrd to initially insert all the elements in the list. o You may use the following function to fill the list: void fill(orderedArrayListType& list) { int seed = 47; int multiplier = 2743; ...
(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
C++ C++ C++ Write a program that will provide evidence as to which algorithm will search an array faster, Linear (sequential) search or Binary Search. Your program should test many different scenarios. Please help with right answer.
Course: CIS-5, Intro to Programming
1. Which algorithm is also called the sequential search? binary search linear search bubble sort selective sort 2 Which search algorithm requires that the elements be pre-sorted? linear search bubble sort binary search We were unable to transcribe this image
C++ Sequential Search and Binary Seach Write a set of code that will include Sequential and Binary Search that will have a set of 25. This solution must include: seqArray [] = {25 unsorted #s} binArray [] = {25 sort #s} while loop repeat = y { switch case 1 seq case 2 bin
I need question 9-10 answered. Thank you
Question 1 iShow the resulting binary search tree if we are to insert following elements into the tree in given order, [34, 12, 23, 27,31,9,11,45, 20, 37. i) Show the resulting balanced binary search tree if we are to insert following sorted elements into the tree, [9,12,21, 23, 29, 31, 34, 45, 48, 52, 55] iii What is the pre-order traversal of the balanced binary search tree? v) What is the post-order traversal...
Write an algorithm that will check if a tree is a binary search tree. If a tree is not a binary search tree, then it will repair it to make it one. (a) Write pseudo-code for both functions. (b) What is the running time for your algorithm?