Construct a graph from given degrees of all vertices | A function to print the adjacency matrix . ; n is number of vertices ; For each pair of vertex decrement the degree of both vertex . ; Print the result in specified form ; Driver Code
def printMat ( degseq , n ) : NEW_LINE INDENT mat = [ [ 0 ] * n for i in range ( n ) ] NEW_LINE for i in range ( n ) : NEW_LINE INDENT for j in range ( i + 1 , n ) : NEW_LINE INDENT if ( degseq [ i ] > 0 and degseq [ j ] > 0 ) : NEW_LINE INDENT degseq [ i ] -= 1 NEW_LINE degseq [ j ] -= 1 NEW_LINE mat [ i ] [ j ] = 1 NEW_LINE mat [ j ] [ i ] = 1 NEW_LINE DEDENT DEDENT DEDENT print ( " ▁ " , end = " ▁ " ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT print ( " ▁ " , " ( " , i , " ) " , end = " " ) NEW_LINE DEDENT print ( ) NEW_LINE print ( ) NEW_LINE for i in range ( n ) : NEW_LINE INDENT print ( " ▁ " , " ( " , i , " ) " , end = " " ) NEW_LINE for j in range ( n ) : NEW_LINE INDENT print ( " ▁ " , mat [ i ] [ j ] , end = " " ) NEW_LINE DEDENT print ( ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT degseq = [ 2 , 2 , 1 , 1 , 1 ] NEW_LINE n = len ( degseq ) NEW_LINE printMat ( degseq , n ) NEW_LINE DEDENT