Breadth-First Search (BFS)
Level Order Traversal:
Visit nodes level-by-level and left-to-right fashion at the same level. Here, the traversal is level-wise. It means that the most left child has traversed first and then the other children of the same level from left to right have traversed.
void solver(Node* root){
queue<Node*> q;
q.push(root);
while(!q.empty()){
Node* node = q.front();
q.pop();
cout<<node ->data<<" ";
if(node ->left != NULL)
q.push(node ->left);
if(node ->right != NULL)
q.push(node ->right);
}
}
🥇 🥇 🥇
Other Important Questions List
Practice Questions List
💯 🔥 🚀