Question

In: Computer Science

Let A be an integer array of length n. Design a divide and conquer algorithm (description...

Let A be an integer array of length n.

Design a divide and conquer algorithm (description and pseudo code) to find the index of an element of the minimum value in the array.

If there are several such elements, your algorithm must return the index of the rightmost element.

For instance, if A = {0,2,4,5,2,0,3,10}, then the algorithm should return 5, which is the index of the second 0.

Solutions

Expert Solution

Pseudo Code ==>

index( arr[ ], n)

{

min = arr[0];

for(int i=0;i<n;i++)

{

if(min>arr[i])

{

min=arr[i];

}

}

for( int i=n-1;i>=0;i--)

{

if(arr[i]==min)

{

return i;

}

}

}

main()

{

arr[ ];

size = sizeof(arr)/sizeof(arr[0]);

minIndex = index(arr,size);

print “ Index is “ ,minIndex;

}

C++ CODE for THIS ===>

#include <iostream>

using namespace std;
int index(int arr[],int n)
{

int min = arr[0];

for(int i=0;i<n;i++)
{
if(min>arr[i])
{
min=arr[i];
}
}

for( int i=n-1;i>=0;i--)
{
if(arr[i]==min)
{
return i;
}
}

}
int main()
{
int arr[]= {0,2,4,5,2,0,3,10};
int size = sizeof(arr)/sizeof(arr[0]);
cout<<"Index of the rightmost minimum element : "<<index(arr,size)<<endl;
return 0;
}

OUTPUT SCREENSHOT ===>


Related Solutions

Given an array of positive integers except one negative integer. Develop a divide-conquer algorithm to find...
Given an array of positive integers except one negative integer. Develop a divide-conquer algorithm to find the index of the negative integer, and compute its average complexity.
3. Suppose that a divide and conquer algorithm for multiplication of n x n matrices is...
3. Suppose that a divide and conquer algorithm for multiplication of n x n matrices is found such that it requires 6 multiplications and 31 additions of n/2 x n/2 submatrices. Write the recurrence for the running time T(n) of this algorithm and find the order of T(n).
Design and analyze a divide-and-conquer algorithm for finding the maximum element in a list: L[0: n – 1].
The following submission rules apply:·    For those questions requiring programs, the solutions must be implemented using JavaScript or Java.o Appropriate self-documenting comments in the source code are mandatory, consistent with good programming practices.o Solutions must be provided in plain text so that formatting is not lost.·    All answers must be provided in this document.·    Sources must be given accurate and complete citations sufficient for the instructor to find and confirm them.Design and analyze a divide-and-conquer algorithm for finding the maximum...
a. Develop a divide-and-conquer algorithm to perform a parallel merge sort of an array. Hint: After...
a. Develop a divide-and-conquer algorithm to perform a parallel merge sort of an array. Hint: After division, each process sorts its part of the array using an efficient algorithm. Then, the subarrays are merged into larger sorted subarrays. b. Analyze the communication and computation times if the number of processes is equal to the number of array elements, n. c. Repeat Part b if the number of processes is less than the number of array elements. Assume that the computation...
design a divide & conquer alogrithm that requires 2 recursive calls for array size greater than...
design a divide & conquer alogrithm that requires 2 recursive calls for array size greater than 2. the algorithm should receive an array of ints and output the product of the array. provide the reccurence equation and the big-oh analysis/tightest bound. and show the run-time if input to the algorithm passed the entire original array into the recursive call
Let iqsort(A, 1, n) be an algorithm that sorts an array A with n integers. It...
Let iqsort(A, 1, n) be an algorithm that sorts an array A with n integers. It works as follows: iqsort(A, p, q){ if p ≥ q, return; r=partition(A, p, q); //run quick sort on the low part quicksort(A, p, r − 1); //run insert sort on the high part insertsort(A, r + 1, q); } Compute the best-case, worst-case, and average-case complexities of iqsort.
Divide and conquer approach to find the minimum absolute difference in array A[lo..hi] Input an array...
Divide and conquer approach to find the minimum absolute difference in array A[lo..hi] Input an array A[lo..hi] of n real numbers. Requirement: Shouldn't use a sorting algorithm. Complexity O(nlgn)
DIVIDE AND CONQUER Implement the two algorithms for finding the kth smallest integer in a set...
DIVIDE AND CONQUER Implement the two algorithms for finding the kth smallest integer in a set of integers using only one array that contains all the integers. Test your programs and compute the CPU time for different sets of integers generated by a random number generator. Must sure have the CPU time.
The following divide-and-conquer algorithm is designed to return TRUE if and only if all elements of...
The following divide-and-conquer algorithm is designed to return TRUE if and only if all elements of the array have equal values. For simplicity, suppose the array size is n=2k for some integer k. Input S is the starting index, and n is the number of elements starting at S. The initial call is SAME(A, 0, n). Boolean SAME (int A[ ], int S, int n) { Boolean T1, T2, T3; if (n == 1) return TRUE; T1 = SAME (A,...
Q. Explain how a divide and conquer algorithm for detecting whether or not the number 5...
Q. Explain how a divide and conquer algorithm for detecting whether or not the number 5 exists in an array would work. Your explanation should include: - a description of your algorithm using psuedocode - a proof of correctness of your algorithm - an analysis of the runtime of the algorithm
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT