Question

In: Computer Science

Q. A sequence X1, X2, ... , Xn is said to be cyclically sorted if the...

Q. A sequence X1, X2, ... , Xn is said to be cyclically sorted if the smallest number in the sequence is Xi for some unknown ?, and the sequence Xi, Xi+1, Xn, ... , X1, X2,....Xi-1 is sorted in an increasing order. Design an algorithm to find the position of the minimal element in a cyclically sorted ? distinct elements. (6 points) If your algorithm uses recursion, you need so show the recurrence function. Otherwise, show a closed-end form of the running time function. (2 points) Show that your algorithm in ?(log ?) time. (2 points) (No need to prove the bound).

Solutions

Expert Solution

The cyclically sorted array has a minimal element in the whole list X1,X2, ....,Xn we can use binary search to do this. keep finding middle element and check if the element to it's left is greater than itself. This is the smallest element. Check if the first element is zero. Algorithm is as below using recursion

1. Take array, lower index and higher index as input to function and return index of smallest element

2. last element is left, if high == low return high

3. check if element doesn't exist if (high < low) return 0

4.   Find mid, mid = (low + high)/2

5. Check if element mid is minimum element.

6. if arr[mid] < arr[mid - 1] && mid > low , return mid second condition to be checked as mid-1 element can go out of bound for particular iteration

7. Check if we should proceed with left or right subarray. if element at position high is bigger than middle element cll function at step 1 for lower half else proceed with upper half

Recurrence function

T(n) = T(n/2) + c reducing by half plus constant time c

Time complexity

The problem cuts down to half of length passed to function everytime. this cuts down complexity by half every time.

T(n) = T(n/2) + c

T(n) = T(n/4) + c1 where c1 = c + another constant time

T(n) = T(n/8) + c2

This comes out to log n Hence the time complexity is O(log n)

       


Related Solutions

A sequence of integers x1,x2,...,xn is unimodal if for some 1 ≤ i ≤ n we...
A sequence of integers x1,x2,...,xn is unimodal if for some 1 ≤ i ≤ n we have x1 < x2 < ... < xi and xi > xi+1 > ... > xn. Find the maximum element in a unimodal sequence of integers x1, x2, . . . , xn. The running time should be O(log n). Show that your algorithm meets the bound.
Let X = {x1,x2,...,xn} a sequence of real numbers. Design an algorithm that in linear time...
Let X = {x1,x2,...,xn} a sequence of real numbers. Design an algorithm that in linear time finds the continue subsequence of elements xi,xi+1,...,x, which product is the maximum. Suppose that the product of an empty subsequence is 1 and observe that the values can be less to 0 and less to 1.
a real sequence xn is defined inductively by x1 =1 and xn+1 = sqrt(xn +6) for...
a real sequence xn is defined inductively by x1 =1 and xn+1 = sqrt(xn +6) for every n belongs to N a) prove by induction that xn is increasing and xn <3 for every n belongs to N b) deduce that xn converges and find its limit
: Let X1, X2, . . . , Xn be a random sample from the normal...
: Let X1, X2, . . . , Xn be a random sample from the normal distribution N(µ, 25). To test the hypothesis H0 : µ = 40 against H1 : µne40, let us define the three critical regions: C1 = {x¯ : ¯x ≥ c1}, C2 = {x¯ : ¯x ≤ c2}, and C3 = {x¯ : |x¯ − 40| ≥ c3}. (a) If n = 12, find the values of c1, c2, c3 such that the size of...
. Let X1, X2, . . . , Xn be a random sample from a normal...
. Let X1, X2, . . . , Xn be a random sample from a normal population with mean zero but unknown variance σ 2 . (a) Find a minimum-variance unbiased estimator (MVUE) of σ 2 . Explain why this is a MVUE. (b) Find the distribution and the variance of the MVUE of σ 2 and prove the consistency of this estimator. (c) Give a formula of a 100(1 − α)% confidence interval for σ 2 constructed using the...
Let X1,X2, . . . , Xn be a random sample from the uniform distribution with...
Let X1,X2, . . . , Xn be a random sample from the uniform distribution with pdf f(x; θ1, θ2) = 1/(2θ2), θ1 − θ2 < x < θ1 + θ2, where −∞ < θ1 < ∞ and θ2 > 0, and the pdf is equal to zero elsewhere. (a) Show that Y1 = min(Xi) and Yn = max(Xi), the joint sufficient statistics for θ1 and θ2, are complete. (b) Find the MVUEs of θ1 and θ2.
Consider the independent observations x1, x2, . . . , xn from the gamma distribution with...
Consider the independent observations x1, x2, . . . , xn from the gamma distribution with pdf f(x) = (1/ Γ(α)β^α)x^(α−1)e ^(−x/β), x > 0 and 0 otherwise. a. Write out the likelihood function b. Write out a set of equations that give the maximum likelihood estimators of α and β. c. Assuming α is known, find the likelihood estimator Bˆ of β. d. Find the expected value and variance of Bˆ
Let X1, X2, . . . , Xn be iid following a uniform distribution over the...
Let X1, X2, . . . , Xn be iid following a uniform distribution over the interval (θ, 2θ) (θ > 0). (a) Find a method of moments estimator of θ. (b) Find the MLE of θ. (c) Find a constant k such that E(k ˆθ) = θ. (d) By using the Rao-Blackwell, which estimators of (a) and (b) can be improved?
Let X1, X2, . . . , Xn be a random sample of size n from...
Let X1, X2, . . . , Xn be a random sample of size n from a Poisson distribution with unknown mean µ. It is desired to test the following hypotheses H0 : µ = µ0         versus     H1 : µ not equal to µ0 where µ0 > 0 is a given constant. Derive the likelihood ratio test statistic
Consider n numbers x1, x2, . . . , xn laid out on a circle and...
Consider n numbers x1, x2, . . . , xn laid out on a circle and some value α. Consider the requirement that every number equals α times the sum of its two neighbors. For example, if α were zero, this would force all the numbers to be zero. (a) Show that, no matter what α is, the system has a solution. (b) Show that if α = 1 2 , then the system has a nontrivial solution. (c) Show...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT