Google interview question

Given a graph node, write a code to return a copy of the sub-graph starting with that node.

Interview Answers

Anonymous

4 Sept 2012

binary tree is not the only type of graph. How would you handle cycles? What about self references etc?

1

Anonymous

8 Sept 2012

This question is ill-defined. Is it an undirected graph a directed graph or a random graph whose edges are selected with probability p?

1

Anonymous

21 Oct 2012

question is what is "sub-graph" start with a node

Anonymous

3 Jul 2012

jk. But the code probably looks like this. GetSubTreeCopy(Node n) { Node n1= new Node(); n1.x=n.x; if(n.left !=null) { Node n2= GetSubTreeCOpy(n.left); n1.left=n2; } if(n.right !=null) { Node n2= GetSubTreeCOpy(n.right); n1.right=n2; } return n1; }