abc Interview Question for Developer Program Engineers


Team: code
Country: India




Comment hidden because of low score. Click to expand.
0
of 0 vote

This answer applies only if no two nodes(vertices) can be connected twice, and that no node can be connected to itself.

To connect all the nodes you have in a graph, you have to have a minimum of n-1 edges. So n-1=n, then:

when k=1, then you can connect n vertices
when n>k>1, then you can connect n-k+1 vertices
when k=n, you can connect 0 edges

- vi.ramanauskas November 13, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Directed graph can have max = (n * (n-1)) / 2 edges
Undirected graph can have max = (n * (n-1))
A Tree can have max of n-1 edges

Are u answering assuming that it is as tree?

- Algorithmy November 14, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Yeah you got me there :D. From information that was provided, I assumed it was an undirected graph. In that case having more than n-1 doesn't increase the amount of vertices you can connect. It is entirely different story ) if it is a directed graph... In that case you have to have additional information provided. E.g. whether it is strongly connected or not.
My graph theory knowledge is very rusty (Wonder what would they say if I asked them to tell me what a graph is, or the rules that define it) so please correct me if I am wrong or missed something.

- vi.ramanauskas November 14, 2014 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More