Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Directed graph and multiple edges are given as a single component. Determine whether the graph is a tree or not. In this case, it is required to determine if the graph is a cyclic graph (Contains Cycles) which contains a path from at least one node back to itself


Implement the following isTree function to return true or false as a description for the given graph.



"" static bool IsTree(string[] vertices, List<keyvaluepair<string, string="">> edges) ""


Thanks in advance

What I have tried:

this is the function that i have to code ... i know the logical idea using the DFS but i need some help to implement it cuz iam studying on my own
Posted
Updated 5-Jan-21 12:33pm

1 solution

Quote:
Determine whether the graph is a tree or not
Well use the basic hint to see whether a graph is a tree or not; a tree is a graph that doesn't allow going from a child node to a parent node.

I can also give you a hint, that the space complexity of this could be O(N) since you need to know if you are ever visiting a parent node.

Good luck!
Quote:
if the graph is a cyclic graph (Contains Cycles) which contains a path from at least one node back to itself
Read the 2 paragraphs above and you will be able to understand what I mean.
 
Share this answer
 
Comments
Mostafa Ayman 5-Jan-21 23:51pm    
thanks Afzaal,
but actually my problem not in this point i got the logic pretty well but i can't code it so what is need if you can help me or coding or show me a coded example
Member 15611513 22-Apr-22 15:42pm    
did you get the code bro ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900