Solution:
Let n = is the size of items in an array
Let T (n) = time required to apply the algorithm on an array of size n. Here we divide the terms as T(n/2).
1 here tends to the comparison of the minimum with minimum as in above given algorithm.
Thus, T(n) can be written as
T(n) = T(n/2) + T(n/2) + 1
or
T(n) = 2T(n/2) + 1
We can solve this using master's method as below:
a = 2, b = 2, f(n) = 1, c = 0 as n0 = 1, logba = log22 = 1
We observe that c < logba; case 1 applies. So Solution would be:
T(n) = theeta(nlogba) = theeta(n1) = theeta(n).
Please give thumbsup, if you like it. Thanks.
Question 1. Below is the pseudo code for a divide and conquer algorithm that finds the...
need help in this algorithm question Let A be an array containing n numbers (positive and negative). Develop a divide and conquer algorithm that finds the two indices 1 sisjsn such that A[k] (the sum of the elements from i to j) is maximized. For example, in the array A [10,-5,-6,5, 7,-2,4, -11], the sub-array A[4:6] has the sum 5+ 7-2+4-14 and no other sub-array contains elements that sum to a value greater than 14, so for this input the...
Use a loop invariant to prove that the following algorithm correctly identifies the location of the minimum value in the array data. Input: data: array of integers Input: n: size of data Output: index min such that data[min] <= data[i] for any i from 1 to n Algorithm: FindMin min = 1; for i = 2 to n do if data[i] < data[min] then min = i; end end return min
Suppose that, in a divide-and-conquer algorithm, we always divide an instance of size n of a problem into 5 sub-instances of size n/3, and the dividing and combining steps take a time in Θ(n n). Write a recurrence equation for the running time T (n) , and solve the equation for T (n) 2. Suppose that, in a divide-and-conquer algorithm, we always divide an instance of size n of a problem into 5 sub-instances of size n/3, and the dividing...
A divide-and-conquer algorithm solves a problem by dividing the input (of size n>1, T(1) =0) into two inputs half as big using n/2-1 steps. The algorithm does n steps to combine the solutions to get a solution for the original input. Write a recurrence equation for the algorithm and solve it.
A divide-and-conquer algorithm solves a problem by dividing the input (of size n>1, T(1) =0) into two inputs half as big using n/2-1 steps. The algorithm does n steps to combine the solutions to get a solution for the original input. Write a recurrence equation for the algorithm and solve it.
1. Design and write a Divide& Conquer algorithm that, given an array A of n distinct integers which is already sorted into ascending order, will find if there is some i such that Ali] in worst-case 0(log n) time.
6.) (a) A string contains several X's followed by several O's. Devise a divide-and-conquer algorithim that finds the number of X's in the string in log2n steps, where n is the length of the string. (b) An array originally contained different numbers in ascending order but may have been subsequently rotated by a few positions. For example, the resulting array may be: 21 34 55 1 2 3 4 5 8 13 Is it possible to adapt the Binary Search...
8. (1) Implement the minimum subsequence sum using divide-and-conquer. (30 points) (2) For the array =[4-3 5-2-1 2 6-2, you should provide the solution using the minimum subsequence sum like the example in class. Test the sample for your code. (3) Obtain the T(n) expression for the above algorithm
You have to write your code in C++ (as a cpp file) and prepare a docx file that formally explains the complexity of your implemented algorithm (using recurrence relations). For details, please read the questions carefully. Question 1: Use a divide and conquer approach based algorithm that finds the largest item in a given array of size n. Analyze your algorithm and show the complexity by solving its recurrence relation (cpp file for the code and a docx file for...
Problem 6(15 Points) MARIE Assembly Programming Develop a MARIE program containing a main function which finds the smallest element of an array T is shown below. The passing arguments and one subroutine function called Sindmin findmin function array and the aro the findmin subroutine functon are the beginning e pseudo code for the subroutine elements of Array1 and Arra array size Continue the following MARIE program to find the smallest ORG 100 Jump Start nt findmin (int "addr, int size)...