graphs class vertex public char label/label ( ' 'public boolean wasvisitedpublic vertex(char lablabel labwasvisited false/end class vertex /constructor vertex objects can be placed in an array and referred to using their index number in our examples we'll store them in an array called vertexlist the vertices might also be placed in list or some other data structure whatever structure is usedthis storage is for convenience only it has no relevance to how the vertices are connected by edges for thiswe need another mechanism edges in "red-black trees,we saw that computer program can represent trees in several ways mostly we examined trees in which each node contained references to its childrenbut we also mentioned that an array could be usedwith node' position in the array indicating its relationship to other nodes "heaps,described arrays used to represent kind of tree called heap graphhoweverdoesn' usually have the same kind of fixed organization as tree in binary treeeach node has maximum of two childrenbut in graph each vertex may be connected to an arbitrary number of other vertices for examplein figure avertex is connected to three other verticeswhereas is connected to only one to model this sort of free-form organizationa different approach to representing edges is preferable to that used for trees two methods are commonly used for graphsthe adjacency matrix and the adjacency list (remember that one vertex is said to be adjacent to another if they're connected by single edge the adjacency matrix an adjacency matrix is two-dimensional array in which the elements indicate whether an edge is present between two vertices if graph has verticesthe adjacency matrix is an nxn array table shows the adjacency matrix for the graph in figure