-
Notifications
You must be signed in to change notification settings - Fork 2
Graph: Clone a directed graph
Mani Bhushan edited this page Aug 14, 2016
·
16 revisions
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.
Do a breadth first search of the input graph and while cloning individual graph nodes, check if you have already created that graph node or not. We can use a hashmap to keep track of already created graph nodes.
- Time Complexity: O(V + E)
- Space Complexity: O(V + E)
CloneGraphDriver.java Send me a pull request if you feel this solution can be improved further.