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

The Array Collection problem accepts a positive integer k and collection of n so

ID: 3737920 • 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 2,4], the solution would be ([1,3,5,2,4]) For example, if k 5 and we are given the arrays [1,3,5], [1.25], [2,3], and 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 . 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 wor Input: G = (V,E): graph with n vertices and m edges Input:n, m: order and size of G Algorithm: FriendOfFriened for EV do afor E N() do for w e N(u) do if v w and e and w are not adjacent then G.AddEdge(e,w) end end end o end 1 return G

Explanation / Answer

// C++ program to print all distinct elements in a given array
#include <iostream>
#include <algorithm>
using namespace std;

void printDistinct(int arr[], int n)
{
   // Pick all elements one by one
   for (int i=0; i<n; i++)
   {
       // Check if the picked element is already printed
       int j;
       for (j=0; j<i; j++)
       if (arr[i] == arr[j])
           break;

       // If not printed earlier, then print it
       if (i == j)
       cout << arr[i] << " ";
   }
}

// Driver program to test above function
int main()
{
   int arr[] = {1,3,5,1,2,5,2,3,2,4};
   int n = sizeof(arr)/sizeof(arr[0]);
   printDistinct(arr, n);
   return 0;
}

#include<iostream>
using namespace std;

int main() {

    int arr[10], i;

    cout << "Enter any 10 Numbers :";
    for (i = 0; i < 10; i++) {
        cin >> arr[i];
    }

    cout << " All Even List is :";
    for (i = 0; i < 10; i++) {
        if (arr[i] % 2 == 0)
            cout << arr[i] << " ";
    }

    cout << " All Odd List is :";
    for (i = 0; i < 10; i++) {
        if (arr[i] % 2 != 0)
            cout << arr[i] << " ";
    }

    return 0;
}