How to build a graph of people where node connections are determined by name and age?
I assume you want to build the graph of all people, with edges between each pair of people at degree 1.  Once you have this graph, it is straightforward to calculate the distance (&quot;degree&quot;) between any two people using standard algorithms.
It's easy to build that graph in adjacency list format; or to store it implicitly and generate the adjacency lists on demand.
Store a hash table that maps from name to a list of all people with that name; and another hash table that maps from age to a list of all people with that age.  Now, given one person, you can use the hash tables to quickly find all other people who have a first-degree relationship with that person, i.e., who are adjacent in the graph.  This lets you build an adjacency list representation of the graph in $O(|V|+|E|)$ time, i.e., linear time rather than quadratic time.
Then, once you have this graph, you can compute distances using BFS in this graph.  Note that you can construct the graph on-the-fly as you execute the BFS algorithm; you don't need to build the entire graph in advance.

Footnote: I'm treating hash table lookups as $O(1)$ time.  This is a reasonable modelling assumption for practical work.  For theoretical work, you can ensure that lookups take $O(1)$ expected time if you use an appropriate hash function, which is nearly as good for most practical purposes.