Graph theory: BFS (Breadth First Search) - why is current processed first? I am referencing some code I found on GeeksForGeeks.com: Why is the current node printed (and processed) first before its children are processed? Wouldn't "breadth first" mean "Process children first, then process parent"? or, is that only for Trees? I can't be the only one to not understand this, so instead of flaming me, somebody please simply post the answer?

void Graph::DFSUtil(int v, bool visited[]) 
{ 
    visited[v] = true; &lt;-- why is this printed FIRST?
    cout &lt;&lt; v &lt;&lt; " "; 

    // Recur for all the vertices adjacent 
    // to this vertex 
    list&lt;int&gt;::iterator i; 
    for (i = adj[v].begin(); i != adj[v].end(); ++i) 
        if (!visited[*i]) 
            DFSUtil(*i, visited); 
} 

// DFS traversal of the vertices reachable from v. 
// It uses recursive DFSUtil() 
void Graph::DFS(int v) 
{ 
    // Mark all the vertices as not visited 
    bool *visited = new bool[V]; 
    for (int i = 0; i &lt; V; i++) 
        visited[i] = false; 

    // Call the recursive helper function 
    // to print DFS traversal 
    DFSUtil(v, visited); 
}
1) In answer to the semantic question "Wouldn't 'breadth first' mean 'Process children first, then process parent'?"

This question is a duplicate of the following: What is the meaning of &#39;breadth&#39; in breadth first search?

2) In answer to the technical question "Why is the current node printed (and processed) first before its children are processed?":

BFS processes nodes in the following order: the starting vertex, then all the vertices at distance 1, then all the vertices at distance 2, etc. As pointed out by @user111398, you need to mark a node as visited before processing it or you will go on an infinite loop if the graph is cyclic. If you mark the parent but don't process it before (marking and) processing its children then you are processing the nodes in the following order: all the nodes at max distance, then all the nodes at max depth minus one, etc. This is reverse-BFS, not BFS.