# Why do basic graph algorithms (BFS, DFS, Prim, Kruskal) have a similar structure?

This is my first post on CS Stack Exchange. For some time, I have been studying basic graph algorithms, mainly BFS, DFS, minimum spanning trees and their basic algorithms (Kruskal and Prim). One thing I have noticed, as I have used both Skiena's Algorithm Design Manual and CLRS is that, at least in the pseuducode in CLRS, several of them have a similar structure: do something with all the vertices of the graph, do something special to the root or the first vertex (for example, set its cost to 0, as in Prim), then create a queue or a priority queue, insert all the vertices and in a loop extract one by one, check some condition and do something to their adjacency list. Why do they follow such a structure? Some of the algorithms in CLRS are similar:

PS: as I mentioned, this is my first post, not only in CS, but in all the Stackoverflow network. Any suggestion or improvement on question posting is greatly appreciated.

But this is not necessary, we may solve problems in very strange ways. Take this example when we want to check if there does not exist a path from $$u$$ to $$v$$ in the input graph with $$n$$ number of vertices which path lengths has a size of $$O(n)$$ and we are limited to logarithmic space, the algorithm which introduced by Immerman-Szelepcśenyi is not trivial at all.