I am looking for a computationally-efficient method to generate a complete list of the triangles in a given graph. For the purposes of this question, we give each vertex a letter name, and a triangle is recorded by writing the three letters. Although the order of the letters does not matter, only one of the possible orders should be recorded (i.e. you may record "EFA", "FEA", "AFE", "FAE", "EAF", or "AEF", but only one of them).
Each vertex has a reference to every other vertex. The algorithm starts with a single vertex, which is assumed to be connected in some way to every other point in the graph. For instance, if we started with E in the example image, we could then move to F, A, or B and continue until we record every triangle in the graph.
A triangle is defined as a group of three vertices that are connected to each other, but do not contain any points within them. In the example graph, while ABD, ACD, and BDC are all triangles, ABC is not. (In this case, the complete set of triangles is EAB, EAF, AFG, AGC, ADB, ADC, BDC.)
For my particular purposes, the graph happens to have the assumption that every enclosed shape in the graph is a triangle. For instance, in this example, removing the edge AB would make the graph invalid, since EBDA would be a quadrilateral. Also, there are no "hanging" edges - every edge borders at least one triangle. A graph that does not meet these conditions does not need to be considered.



Enumerate edges and make sure that end points of each edge are listed in alphabetical order. The following program will simply go through the list of edges, check if they have a common point and if they do, it will check if the remaining two points also constitute an edge in the input set.
The program prints: