3. Depth of a Node #

Created Wednesday 29 January 2020

Depth: Level wise distance from root. hence depth(root) = 0.

Q) Print all node at depth d. A) Recursion for 95 %. Whenever is seems intractable, use what we know. f(k, root) = for i in root.children: f(k-1, root->children.at(i)); if(k==0) cout << root->data << " "; // if it is a leaf node for is not executed. Returned.

for(int i=0; i < root->children.size(); i++) f(root->children.at(i), k-1);