Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The maximum coverage problem is that given an integer k and a list of n finite s

ID: 3835478 • Letter: T

Question

The maximum coverage problem is that given an integer k and a list of n finite sets S1, S2,...., Sn, select k sets from the n sets to have maximum size of union. This is one of the classical NP-hard problems.

1. Write a program to implement the greedy algorithm:

Mark all n sets S1, S2,..., Sn as unselected.

Repeat k times

Select one set that has the maximum number of elements not in the union the already selected sets.

2. Write a randomized implementation for the greedy algorithm. Let m be a parameter that controls the number of random samples.

Mark all n sets Si, S2, ...., Sn as "unselected".

Repeat k times

{ For each unselected set Si,

{ Select m random samples r1, r2,..., rm from Si.

Compute mi to be the number of elements from the m random elements that are not in the union of selected set.

}

Select set Si such that mi is the largest and mark it as "selected".

}

3. Test your two algorithms when each set Si is the set of all integers in an interval [a, a+h], where a and h are integers. You can consider that each a is in the range [1, 100000], n=1000, and h=5000. Run your program for the cases m=10, 100, 200, and 500, respectively. Compare the performance between the algorithms 1 and 2 in both running time and the size of the union of k selected sets. Please use the function int MaxCov(int **A, int k, int n, int B[ ]), where A is used to hold the list of n sets, k is the parameter for the number of sets to be selected, n is the number of input sets, and B[ I stores the indices of selected sets. It returns an integer for the size of the union of .k selected sets.

Explanation / Answer

2)

1. If low >= high, then EXIT.

2. as pivot 'x' is not a middle Pivot.

(i) decide consistently at random a number as of [low..high].

Let the arbitrarily chosen figure number be x.

(ii) Count elements in arr[low..high] that are lesser

than arr[x]. Let this count be sc.

(iii) Count rudiments in arr[low..high] that are greater

than arr[x]. Let this count be gc.

(iv) Let n = (high-low+1). If sc >= n/4 and

gc >= n/4, then x is a middle pivot.

3. Partition arr[low..high] approximately the pivot x.

4. // Recur for lesser elements

randQuickSort(arr, low, sc-1)

5. // Recur for better elements

randQuickSort(arr, high-gc+1, high)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote