Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Ok you asked for more detail on my previously submitted question.This is a picture of the solution that a Chegg expert sent in response to
Ok you asked for more detail on my previously submitted question.This is a picture of the solution that a Chegg expert sent in response to my "classic find the celebrity algorithm" problem. The problem is to code in Python the most efficient way (worst case linear), when given an adjacency matrix (to be used as the input) for an aquaintance graph, to find the celebrity (if there is one) by checking the fewest possible matrix entries. A celebrity is a person who knows nobody but is known by everyone. The output should be a list in which the first element is the celebrity number(or -1 if no celebrity present) and the second element is the number of checks (comparisons)to entries in the matrix.This code in this solution a Chegg expert sent seems to find the celebrity fine but is inaccurate on the number of checks (2nd element in output) it makes. I know this because if I use the adjacency matrix [[0,1,1,1],[1,01,1],[1,1,0,1],[1,0,0,0],] is outputs a celebrity id of -1 (which is correct) but says the number of checks is 1 which is impossible. Please fix this code! Thanks
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started