isthere is no edge from the vertex to the vertex ' 'on the other handreads as trueindicating that there is an edge it is often useful to use boolean values hererather than the numbers and because it allows us to carry out operations on the booleans in the second casewe have weighted graphand we have the real-valued weights in the matrix insteadusing the infinity symbol to indicate when there is no edge for an undirected graphif there is in the ith column and the jth rowwe know that there is an edge from vertex to the vertex with the number jwhich means there is also an edge from vertex to vertex this means that adj[ ][ =adj[ ][iwill hold for all and from to so there is some redundant information here we say that such matrix is symmetric it equals its mirror image along the main diagonal mixed implementation there is potential problem with the adjacency/weight matrix representationif the graph has very many verticesthe associated array will be extremely large ( , entries are needed if the graph has just verticesthenif the graph is sparse ( has relatively few edges)the adjacency matrix contains many and only few sand it is waste of space to reserve so much memory for so little information solution to this problem is to number all the vertices as beforebutrather than using two-dimensional arrayuse one-dimensional array that points to linked list of neighbours for each vertex for examplethe above weighted graph can be represented as followswith each triple consisting of vertex nameconnection weight and pointer to the next triple if there are very few edgeswe will have very short lists at each entry of the arraythus saving space over the adjacency/weight matrix representation this implementation is using so-called adjacency lists note that if we are considering undirected graphsthere is still certain amount of redundancy in this representationsince every edge is represented twiceonce in each list corresponding to the two vertices it connects in javathis could be accomplished with something likeclass graph vertex[headsprivate class vertex int namedouble weightvertex next//methods for vertices //methods for graphs