Let A be an unsorted array of n numbers FindMinA If size of
Solution
Let the number of elements in A is 3n then
a) T(3n) = 3T(n)+cn
or
T(n)=3T(n/3)+cn
Patitioning can be done in O(n) time and FindMin(A) can be solved by recursively calling algorithm three times. for that the term 3T(n/3)
By combining these two we get T(n)=3T(n/3)+cn;
b) T(n)=3T(n/3)+c n
This equation can be solved easily using Master\'s therorem. ie Using master\'s theorem we can prove that T(n)=nlog3n.
c)Correctness of FindMin[A] by Induction
Base case : Consider an array of 1 element (which is the base case of the algorithm). Since the array has only one element and number of elements is less than 5 the algorithm returns that element as minimum. This proves the base case.
Inductive Hypothesis:
Assume that FindMin correctly finds min for k=1, 2, ..., 3n elements
Inductive Step:
Show that FindMin correctly works for k = 3n + 1 elements.
By the Inductive Hypothesis, since ceiling(k/3) < 3n:
x is a minimum of first k/3 elements in A1
y is a minimum of middle k/3 elements in A2
z is a minimum of last k/3 elements in A3
Then, by the correctness of the Findmin algorithm, FindMin returns the Minimum elements in the combined A1+ A2+A3 array. Furthermore, the resulting array contains all the elements of A (i.e., all k = 3n + 1 elements).
The algorithm terminates because we recursively reduce the size of each array by a factor of 3. Eventually each such array contains a single element, in which case the if statement causes Algorithm FindMin to return.
Hence the proof.
![Let A be an unsorted array of n numbers FindMin[A] If size of A is at most 5 then return the minimum value in this array. Else {Partition A into three arrays A Let A be an unsorted array of n numbers FindMin[A] If size of A is at most 5 then return the minimum value in this array. Else {Partition A into three arrays A](/WebImages/38/let-a-be-an-unsorted-array-of-n-numbers-findmina-if-size-of-1113829-1761591203-0.webp)