Answered step by step
Verified Expert Solution
Link Copied!

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 image text in transcribed
Python Code: MATRIX -[[0, 0, 1, o], [O, 0, 1, 01, [0, 0, 0, 0], [0, 0, 1, 011 def inMatrix(a, b): return MATRIX[a b] def findCelebrity n) a=0 count-0 while (a

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 22nd European Conference Adbis 2018 Budapest Hungary September 2 5 2018 Proceedings Lncs 11019

Authors: Andras Benczur ,Bernhard Thalheim ,Tomas Horvath

1st Edition

3319983970, 978-3319983974

More Books

Students also viewed these Databases questions

Question

List the guidelines for effective listening.

Answered: 1 week ago

Question

2. How will the team select a leader?

Answered: 1 week ago