Trees

Tree data structure is a connected acyclic graph. A graph is a tree if it is connected and the relation m=n-1 holds true, where m is number of edges and n is the number of vertices in the graph. All techniques which are useful in graphs can be leveraged in tree problems. Infact, it is usually easier to deal with trees  than graphs .

tree traversal pseudo code:
dfs traversal , we dont need visited as there is no cycle
void dfs(int u, int p){ // u is current node, p is parent node(last node)
visit(u)
for(auto v:adj[u]){
if(v==p)
continue;
dfs(v,u);
}
}
Time Complexity = O(m+n)
Space Complexity = O(n)