473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Given there are N people, .....

Given there are N people, one of them is such as he is known by everybody but doesn't anybody.

How to identify him?
Also, how to identify whether such a person exist in the given set.
May 18 '09 #1
8 1403
JosAH
11,448 Expert 8TB
@vikrantt
Draw the set of people as a graph: each person is a vertex in the graph and if person A 'knows' person B a directed edge is drawn from vertex A to vertex B.

A person who doesn't know anybody but is known by everybody has no outgoing edges but N-1 incoming edges where N is the number of vertexes in the graph.

kind regards,

Jos
May 18 '09 #2
Hey Jos,
Thanks for replying,

But how do you code it with linear time complexity?
May 18 '09 #3
for simplicity sake we can also assume that the input is given as an adjacency matrix.
May 18 '09 #4
JosAH
11,448 Expert 8TB
@vikrantt
A column j should contain all zeros (node j doesn't know anyone) while a row j (except possibly on the main diagonal) should contain all ones (everybody knows person j). If the diagonal element A[j][j] is one as well then, by definition person j knows itself).

kind regards,

Jos
May 18 '09 #5
yeah,

I got that much. But I do not think this is implementable O(N)...this would result in O(N^2)

Thanks a lot.
May 18 '09 #6
JosAH
11,448 Expert 8TB
@vikrantt
It depends on the meaning of N; if N is the number of vertexes in the graph the computing time is O(N^2), if N is the number of edges in the graph then the computing time is O(N).

kind regards,

Jos
May 18 '09 #7
donbock
2,426 Expert 2GB
This may be a silly question, but ... when you say "linear time complexity" do you mean linear compared to the number of people or linear compared to the number of relationships?

The second interpretation provides a loophole that justifies an O(N^2) algorithm.

Whoops! I don't know why I didn't realize at the time that all I did was restate Jos' cogent post.
May 18 '09 #8
JosAH
11,448 Expert 8TB
@donbock
*ahem* great minds think alike ...

kind regards,

Jos ;-)
May 18 '09 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: J. W. McCall | last post by:
Hopefully a simple question: how do I download a file (jpg image) to my hard drive from a website assuming I have its (the image's) URL? I tried urllib.urlretrieve() and it's not working. I'm...
2
by: Angus McIntyre | last post by:
Can this be done with XPath? I have input XML that is basically of the form: <list> <item att="a">s1</item> <item att="a">s2</item> <item att="b">s3</item> <item att="c">s4</item> <item...
34
by: George Hester | last post by:
<html><head><script>z='yCj45%20zeB0+e%21%29OpA6%2CNTn*mkK0+euxe%23i%24NTn*%2 92%2C%29/%21J6%20%7E%3A%20ScUglJ5%2C%5B3G%3DewU%26q%24Ut%3BDA%3CR@FKyp%3Exv%...
6
by: chiara | last post by:
Hi everybody! I am just at the beginning as a programmer, so maybe this is a stupid question...Anyway,I need to write a function in C to generate generate all possible strings of given length...
12
by: Sabiyur | last post by:
Hi All, Is there any way to find out how much memory is allocated for a given pointer. For example: int *p=new int; I know, compiler keeps the information of how much bytes are allocated...
0
by: 2Barter.net | last post by:
" Given BACK what was freely GIVEN " Inbox 2Barter.net Hide options 9:52 pm (0 minutes ago) From: 2Barter.net <chasingcowtomusic@gmail.com> Signed-By: gmail.com | Mailed-By: gmail.com Date:...
4
by: perryclisbee via AccessMonster.com | last post by:
I have dates of service for several people that range all over each month. ie: patient had dates of service of: 7/3/2006, 7/24/2006 and 7/25/2006. I need to create a new field via a query that...
0
by: SunkenHeights | last post by:
Hi people. Can anyone please tell me how to write into an xml given the context path? I am able to write into the xml given the physical path but when I pass the context path a TransformerException...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.