Skip to content

Graph: Clone a directed graph

Mani Bhushan edited this page Aug 14, 2016 · 16 revisions

Question:

Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors.

High Level Approach: Do a breadth first search of the input graph and while cloning individual graph nodes, do check if you have already created that graph node or not. We can use a hashmap to remind ourselves if we have already created a particular graph node or not.

Time Complexity: O(V + E) Space Complexity: O(V + E)

Clone this wiki locally