There is a group of n people, and for every person in this group there is a list
ID: 3760024 • Letter: T
Question
There is a group of n people, and for every person in this group there is a list of people he/she likes. One of the people has a book that everybody wants to read. Every person can lend the book to other person, but only if he/she likes this person. Is it possible to organize transfer of the book between people in such a way that everybody will have it exactly oncel and in the end it will return to its owner? 1. Formulate this problem as an algorithmic problem: 2. What is this algorithmic problem essentially? 3. Is it possible to solve it in a polynomial time? Explain.Explanation / Answer
The solution is O(n) in time complexity.
Make all of them stand in a row.
Lets say the people are a,b,c,d,e,f,g,h,i,j,.......n
Compare a and b.
if a knows b => a
In either case compare the probable next person in line ie 'c' and repeat the process. Each comparison should eliminate 1 person and have another as the probable person. At the end, the probable person who survives is the certain .
Complexity = O(n)
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.