Question: Write pseudocode for an algorithm that solves the above problem in O(n^2 ) time. Say that you have n people p, Pn. Some pairs of
Write pseudocode for an algorithm that solves the above problem in O(n^2 ) time.

Say that you have n people p, Pn. Some pairs of people are friends. To represent friendship friendships we have sets F1, Fn, where j E F; if pi and Pj are friends. For this problem, we assume that friendship is symmetric: so if i E F; then j e Fi. The goal of the problem is to find two people i, k that share at least two mutual friends. Formally, the goal is to find four people i, j, k, q such that j and q are both in Fin Fk. Put otherwise, we must have i E Fj, j E Fk, ke Fq and q EF;. Note that it is not relevant if j E Fq or if i E Fk. Consider the following problem: INPUT: n sets F1, ..., OUTPUT: four people i, j, k, q as described above or no solution if no such quadruplet exists. (If there exist multiple such quadruplets you only have to return one of them.) En The Problem Write pseudocode for an algorithm that solves the above problem in O(n) time. Make sure to justify that your algorithm runs in O(n) time. Zero credit will be given if it is slower than that, or if no justification of the running time is given. NOTE: to make things simpler, you can think of the sets F; as represented by arrays. So if person P; has a friends then F; is an array F;[O...X 1]. You can NOT assume the arrays are sorted. Say that you have n people p, Pn. Some pairs of people are friends. To represent friendship friendships we have sets F1, Fn, where j E F; if pi and Pj are friends. For this problem, we assume that friendship is symmetric: so if i E F; then j e Fi. The goal of the problem is to find two people i, k that share at least two mutual friends. Formally, the goal is to find four people i, j, k, q such that j and q are both in Fin Fk. Put otherwise, we must have i E Fj, j E Fk, ke Fq and q EF;. Note that it is not relevant if j E Fq or if i E Fk. Consider the following problem: INPUT: n sets F1, ..., OUTPUT: four people i, j, k, q as described above or no solution if no such quadruplet exists. (If there exist multiple such quadruplets you only have to return one of them.) En The Problem Write pseudocode for an algorithm that solves the above problem in O(n) time. Make sure to justify that your algorithm runs in O(n) time. Zero credit will be given if it is slower than that, or if no justification of the running time is given. NOTE: to make things simpler, you can think of the sets F; as represented by arrays. So if person P; has a friends then F; is an array F;[O...X 1]. You can NOT assume the arrays are sorted
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
