# MultiAspect Graphs: Algebraic Representation and Algorithms
## 4 MAG Algorithms
### Degree
#### 4.3.2 Degree of Sub-Determined Vertices  
We can determine the degree for sub-determined composite vertices in a similar way to the degree of composite vertices. Given a MAG \(H\) and a sub-determination \(\zeta\), the degree of the sub-determined composite vertices can be obtained by Algorithm 9, where \(|\mathbb{V}_{\zeta}(H)|\) is the number of \(\zeta\) sub-determined composite vertices on MAG \(H\), \(S_{\zeta}\) is the function that takes a composite vertex to its sub-determined form, and \(D_{\zeta}\) is the function that takes the sub-determined composite vertex to its numerical representation. It can be seen that the time complexity of Algorithm 9 is the same as the time complexity of Algorithm 8. ```
input :\(H=(A,E)\), and \(\zeta\) output :\(indegree\), \(outdegree\)
1 SubDetDegree(\(H\), \(\zeta\))
2\(n\leftarrow|\mathbb{V}_{\zeta}(H)|\)
3\(T\gets CompTuple(A(H))\)// companion tuple of H, i.e., \(\tau(H)\)
4\(T_{\zeta}\leftarrow\tau_{\zeta}(H)\)// \(\zeta\) sub-determined companion tuple
5\(indegree\leftarrow\) vector of \(n\) integers, all 0
6\(outdegree\leftarrow\) vector of \(n\) integers, all 0
7 for each \(e\in E(H)\)do
8\(o\leftarrow D(\tau_{o}(e),T_{\zeta})\)// numerical sub-determined origin
9\(d\leftarrow D(\tau_{d}(e),T_{\zeta})\)// numerical sub-determined destination
10\(indegree[d]\gets indegree[d]+1\)
11\(outdegree[o]\gets outdegree[o]+1\)
12
13 end for returnindegree,outdegree
```  
**Algorithm 9**Sub-determined degree. It is important to note that two distinct composite vertices may have the same sub-determined form. This happens when the two composite vertices differ only on aspects which are dropped by the sub-determination. In this case, the degree of each of these composite vertices is summed for obtain the sub-determined degree. From this, it can also be seen that some edges in the sub-determined form may become self-loops. The degrees calculated by Algorithm 9 include the self-loop edges. This algorithm can be modified to count the self-loops separately, as shown in Algorithm 10. This algorithm is similar to Algorithm 8 and has the same time complexity. The sub-determined composite vertices degree can also be determined algebraically with  
\[indegree=\mathbf{M}_{\zeta}(H)\ \mathbf{J}(H)^{T}\ \mathbf{1}, \tag{38}\]\[outdegree=\mathbf{M}_{\zeta}(H)\;\mathbf{J}(H)\;\mathbf{1}, \tag{39}\]  
where \(\mathbf{M}_{\zeta}(H)\) is the sub-determination matrix and \(\mathbf{1}\) is the all 1s column vector, both defined in Section 4.1. Note that the multiplication by \(\mathbf{M}_{\zeta}(H)\) adds the degrees of the composite vertices that are collapsed to the same sub-determined vertex. ```
input :\(H=(A,E)\), and \(\zeta\) output :\(indegree\), \(outdegree\), \(selfdegree\)
1 SubDetDegreeSepLoops(\(H\),\(\zeta\))
2\(n\leftarrow|\mathbb{V}_{\zeta}(H)|\)
3\(T\gets CompTuple(A(H))\)// companion tuple of H, i.e., \(\tau(H)\)
4\(T_{\zeta}\leftarrow\tau_{\zeta}(H)\)// \(\zeta\) sub-determined companion tuple
5\(indegree\leftarrow\) vector of \(n\) integers, all 0
6\(outdegree\leftarrow\) vector of \(n\) integers, all 0
7\(selfdegree\leftarrow\) vector of \(n\) integers, all 0
8 for each \(e\in E(H)\)do
9\(o\gets D(\tau_{o}(e),T_{\zeta})\)// numerical sub-determined origin
10\(d\gets D(\tau_{d}(e),T_{\zeta})\)// numerical sub-determined destination
11 if\(d\
eq o\)then
12\(indegree[d]\gets indegree[d]+1\)
13\(outdegree[o]\gets outdegree[o]+1\)
14
15 end if
16 else
17\(selfdegree[o]\gets selfdegree[o]+1\)
18
19 end for
20
21 end for return\(indegree\),\(outdegree\),\(selfdegree\)
```  
**Algorithm 10**Sub-determined degree, separating self-loops  
The degrees calculated by Equations (38) and (39) include the self-loop edges.