# 1. Please write a Divide-and-Conquer Java algorithm solving the following problem: Given an "almost sorted" array...

###### Question:

1. Please write a Divide-and-Conquer Java algorithm solving the following problem:

Given an "almost sorted" array of distinct integers, and an integer x, return the index of x in the array. If the element x is not present in the array, return -1.

"Almost sorted" means the following. Assume you had a sorted array A[0…N], and then split it into two pieces A[0…M] and A[M+1…N], and move the second piece upfront to get the following:

A[M+1]…A[N]A[0]…A[M].

Thus, the "almost sorted" array is either a sorted array, or it consists of two sorted subarrays, such that every element of the first subarray is greater or equal than every element of the second subarray.

For example, the array {3, 17, 28, 935, 1011, -10, 0, 2} is "almost sorted" since it consists of two sorted subarrays: {3, 17, 28, 935, 1011} and {-10, 0, 2} with the property that each element in the first subarray is greater or equal than every element of the second subarray.

Note: One of the subarrays can be empty, i.e., the array might be sorted.

You need to develop an efficient modification of the Binary Search Algorithm, with worst-case running time of ( ) for an array of n elements.

Reminder: In Java, elements of an array of n elements have indexes 0…n-1.

Formally speaking, your input is an array of distinct integers, and the element x to find; your output is: the index of x in the array, or -1 in case x is not there.

With the array above and x=935, the algorithm has to return 3 (the index of the element 935 in the array).

Please develop the following Java function:

public static int FindIndex(int[] arr, int x)

Here arr is the array of distinct integers, x is the element to find.

NOTE: In your algorithm, you do not have to check that the array is "almost sorted". However, you have to check "boundary cases" like an empty array.

#### Similar Solved Questions

##### Return on Investment The income from operations and the amount of invested assets in each division...
Return on Investment The income from operations and the amount of invested assets in each division of Beck Industries are as follows: Income from Operations Invested Assets Retail Division $81,900$390,000 Commercial Division 86,400 480,000 Internet Division 124,800 780,000 a. Compute the return on ...
##### Calculate the pH of the solution that results from each of the following mixtures. 1. 50.0...
Calculate the pH of the solution that results from each of the following mixtures. 1. 50.0 mL of 0.15 molL−1 HCOOH (Ka=1.8×10−4) with 80.0 mL of 0.13 molL−1 HCOONa 2. 125.0 mL of 0.11 molL−1 NH3 (Kb=1.76×10−5) with 240.0 mL of 0.11 molL−1 NH4Cl Express...
##### Barbituric acid (1) is the backbone for common central nervous system depressants with anesthetic anxiolytic, and...
Barbituric acid (1) is the backbone for common central nervous system depressants with anesthetic anxiolytic, and hypnotic properties. If the active allosteric pharmacophore is present as HA. calculate the a) pH and b) percentage of 2 in 10-M barbituric acid....
##### DIAZ ENTERTAINMENT Cash Account Records May 1, 2021, to May 31, 2021 Cash Balance May 31,...
DIAZ ENTERTAINMENT Cash Account Records May 1, 2021, to May 31, 2021 Cash Balance May 31, 2021 $5,200 Cash Balance Cash May 1, 2021 + Receipts$5,330 $11,790 Cash Receipts Date Desc. 5/3 Sales 5/10 Sales 5/17 Sales 5/24 Sales 5/31 Sales Amount$ 1,410 1,840 2,470 2,940 3,130 Date 5/7 5/12 5/15 5/22 ...
##### The relative molecular weight of acetic acid is 60.05 and its density is 1.049g/ml. Describe how you would prepare 1L of 2M solution of acetic acid?
The relative molecular weight of acetic acid is 60.05 and its density is 1.049g/ml. Describe how you would prepare 1L of 2M solution of acetic acid?...
##### In a closed Hydraulic system, a load is placed on a 4 inch diameter small piston...
In a closed Hydraulic system, a load is placed on a 4 inch diameter small piston and creates 10 psi of pressure. The larger piston is 15 square inches. How much force is created on the small piston? Load Hydraulic Pressure...
##### QUESTION 4 You are given two loans, with each loan to be repaid by a single payment in the future. Each payment include...
QUESTION 4 You are given two loans, with each loan to be repaid by a single payment in the future. Each payment includes both principal and interest. The first loan is repaid by a 3000 payment at the end of four years. The interest is accrued at an annual nominal rate of discount equal to 5% compoun...
##### A function that prints the binary search tree’s all nodes level by level, output statement 50,...
a function that prints the binary search tree’s all nodes level by level, output statement 50, 30, 70, 20, 40, 60, 80 50 / \ 30 70 / \ / \ 20 40 60 80      ...