The Array Collection problem accepts a positive integer k and collection of n so
ID: 3737769 • Letter: T
Question
The Array Collection problem accepts a positive integer k and collection of n sorted arrays containing integers between 1 and k. The output of this problem is a subset of the arrays such that every number 1-k appears in exactly one array, or an empty set, if no solution exists. For example, if k 5 and we are given the arrays [1,3,5, 1,2,5], [2, 3], and 2,4], the solution would be [1,3,5], [2,4]) Answer questions 1 and 2 below about the Array Collection problem 1. Give pseudocode for a greedy algorithm for the Array Collection problem 2. Prove that your algorithm is not correct. (There is no greedy algorithm 3. Find the worst-case time complexity of the FriendOfFriend algorithm be- Note that there is more than one reasonable answer to this problem. that correctly solves this problem.) low when using an adjacency matrix to represent the graph. Show your work. Input: G- (V, E): graph with n vertices and m edges Input: n, m: order and size of G 1 Algorithm: FriendOfFriend 2 for ve V do 3 | for u ? N(v) do for w E N(u) do if u w and u and w are not adjacent then | G.AddEdge(v, w) 5 6 7 8 9end en 10 end 11 return GExplanation / Answer
1 answer
actually these solution is very simple
If u want to best insatiable algo for this problem than u be theoretical to refer this answer.
First of all gluttonous algorithms are not good solution for some questions. Like coin alter problem in dynamic difficulty problems.
now and then greedy algo best pick like Dijkstra algo.
Above problem Solution.
Start -
1) Create k size array and initialize each index as zero [0,0,0,0,etc].
2) As we know rudiments are from 1 to k then Traverse each subsist or Get first subsist or sub array on or after input.
3) increase that number index into that collection index
presume [1,2,4] array([0,0,0,0]) after that after first cross array([1,1,0,1]).
4)If there is not already incremented array index ata that point then add that sublist into final answer.
5) traverse second array and check by now incremented or no if yes then remove that whole sublist.
like wise u know how to traverse and use counting kind technique to address each constituent.
If u want to set of laws of this algorithm then please comment to this react i will provide code of this algo.
since i have lot of code this tye already write.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.