Back to problems

Deep Copy a Graph

Algorithm · Meta · Medium

Create a function that produces a deep clone of an undirected graph. Every graph node stores an integer label along with a collection of adjacent nodes. Define the function as deepClone(node: Node) -> Node, where Node has an integer label and a collection of neighbors containing other Node objects. For instance, this graph: may be written as the adjacency list {5 [6, 7], 6 [5, 8], 7 [5, 8], 8 [6, 7]}. Input/Output Specification Input: The entry node for the undirected graph…

Checking your access…