Employeur impliqué
Given a graph node, write a code to return a copy of the sub-graph starting with that node.
Utilisateur anonyme
binary tree is not the only type of graph. How would you handle cycles? What about self references etc?
This question is ill-defined. Is it an undirected graph a directed graph or a random graph whose edges are selected with probability p?
question is what is "sub-graph" start with a node
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; }
Tenez-vous au courant des dernières opportunités et profitez de conseils d’initiés en suivant les entreprises de vos rêves.
Obtenez des recommandations et des mises à jour personnalisées en démarrant vos recherches.