Algorithm for display nodes of a particular node based on in-degree and out-degree Suppose we have following directed graph. When I click on say node $e$, it should make in-degree and out-degree of node $e$ and connected nodes red. As shown in Resulting Graph. My purpose is, when I click on any node of a directed graph it should tell me what nodes it is influencing(out-degree) and what are nodes which influenced it (in-degree).
I want to make an algorithm for it. I don't know how to make it.

Definition: For a directed graph $G=(V(G), E(G))$ and a vertex $x_1 \in V(G)$, the
Out-Degree of $x_1$ refers to the number of arcs incident from $x_1$. That is, the number of arcs directed away from the vertex $x_1$. The
In-Degree of $x_1$ refers to the number of arcs incident to $x_1$. That is, the number of arcs directed towards the vertex $x_1$.
From mathonline.wikidot.com:


Expected Result:

I want to make mathematical modeling for following pseudo code:

Click on node i (e in example).

look for in-degree relationship r and get nodes(node d in below example).

look for out-degree relationship r and get nodes (node b and f in example).

display the nodes visited    through relationship r including e (expected
result graph).
If you want to highlight the neighbors:
Use adjacency list representation, where each node has a list of all out-edges out of it, and a list of all in-edges into it.  Then given a node you can rapidly identify what to highlight.
If you want to highlight everything connected to that node (at any distance):
Use DFS to find the set of nodes that are reachable from it.