Provide a most efficient divide-and-conquer algorithm for determining the smallest and second
smallest values in a given unordered set of numbers. Provide a recurrence equation expressing
the time complexity of the algorithm, and derive its exact solution in the number of comparisons.
For simplicity, you may assume the size of the problem to be an exact power of a the number 2
Let algorithm be Called minSecondMin(A, p, q) where A is input array with starting index p and ending index q. q-p+1 = n
pseudoCode in C style:-
minSecondMin (A,p,q)// suppose it takes T(n) time
{
if(p +1 == q)
{
if(a[p]>a[q])// here one comparison is done
{
min = a[q]
secondMin = a[p]
}
else
{
min = a[p]
secondMin = a[q]
}
}
else
{
m = floor (p+q/2)
(min1, secondMin1) = minSecondMin (A, p, m)// it takes T(n/2)
(min2, secondMin2) = minSecondMin (A, m+1,q)//it takes T(n/2)
if(min1 > min2)// here 1 comparison
{
min = min2
if(min1>secondMin2)//here 1 comparison
secondMin = secondMin2
else
secondMin = min1
}
else
{
min = min1
if(min2>secondMin1)//here 1 comparison
secondMin = secondMin1
else
secondMin = min2
}
}
}
Recurrence relation for time;-
T(n) = O(1) , if n = 2
= 2T(n/2) + c , if n> 2
Recurrence relation for number of comparisons:-
Let number of comparison = C(n)
Then C(n) = 1 , if n = 2
= 2C(n/2) + 2 , if n > 2
C(n) = 2C(n/2) + 2
Solving using substitution method we get
= 2(2C(n/4) + 2) + 2
= 22C(n/4) + 22 + 2
= 23 C(n/8) + 23 + 22 + 2
Continuing this k times
= 2kC(n/2k) + 2k + 2k-1 + 2k-2 + ...+ 22 + 2
It will stop when n/2k = 2 so k = log2n - 1
= 2log2n - 1 C(1) + 2(2k-1+1 - 1)
= 2log2(n/2) + 2k+1 - 2
= n/2 + 2log2n -2
= n/2 + n - 2
= 3n/2 - 2
So, required number of comparisons = 3n/2 - 2
Provide a most efficient divide-and-conquer algorithm for determining the smallest and second smallest values in a...
Provide a divide-and-conquer algorithm for determining the smallest and second smallest values in a given unordered set of numbers. Provide a recurrence equation expressing the time complexity of the algorithm, and derive its exact solution (i.e., not the asymptotic solution). For simplicity, you may assume the size of the problem to be an exact power of a the number 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 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...
Suppose that, in a divide-and-conquer algorithm, we always divide an instance of size n of a problem into n subinstances of size n/3, and the dividing and combining steps take linear time. Write a recurrence equation for the running time T(n), and solve this recurrence equation for T(n). Show your solution in order notation. please help solve this..
Java program: Convex Hull using Divide and Conquer Algorithm A convex hull is the smallest convex polygon containing all the given points. Input is an array of points specified by their x and y coordinates. The output is the convex hull of this set of points. Examples: Input : points[] = {(0, 0), (0, 4), (-4, 0), (5, 0), (0, -6), (1, 0)}; Output : (-4, 0), (5, 0), (0, -6), (0, 4) use Divide and Conquer Algorithm please explain...
a) Devise a divide-and-conquer algorithm that determines whether the two candidates who received the most votes each received at least n/4 votes and, if so, determine who these two candidates are. [Hint: a candidate could not have received a semi-majority of votes in the overall election without receiving a semi-majority in the first half of votes or a semi-majority in the second half of votes (note: you need to defend this).] b) Use the master theorem to give a big-O...
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.
Suppose that, even unrealistically, we are to search a list of
700 million items using Binary Search, Recursive (Algorithm 2.1).
What is the maximum number of comparisons that this algorithm must
perform before finding a given item or concluding that it is not in
the list
“Suppose that, in a divide-and-conquer algorithm, we always
divide an instance of size n of a problem into n subinstances of
size n/3, and the dividing and combining steps take linear time.
Write a...
Question #4 (15 points) In class, we discussed a divide-and-conquer algorithm for matrix multiplication that involved solving eight subproblems, each half the size of the original, and performing a constant number of e(n) addition operations. Strassen's Algo- rithm, which we did not cover, reduces the number of (half-sized) subproblems to seven, with a constant number of e(n) addition and subtraction operations. Provide clear, concise answers to each of the following related questions. • (7 points). Express the runtime of Strassen's...
You are interested in analyzing some hard-to-obtain data from two separate databases. Each database contains n numerical values—so there are 2n values total—and you may assume that no two values are the same. You’d like to determine the median of this set of 2n values, which we will define here to be the nth smallest value. However, the only way you can access these values is through queries to the databases. In a single query, you can specify a value...