abc Interview Question
Developer Program EngineersTeam: code
Country: India
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?
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.
This answer applies only if no two nodes(vertices) can be connected twice, and that no node can be connected to itself.
- vi.ramanauskas November 13, 2014To 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