Explore BrainMass

Explore BrainMass

    Adjacency Matrix to Adjacency List translation

    Not what you're looking for? Search our solutions OR ask your own Custom question.

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    Find an algorithm to translate the representation of a graph from adjacency matrix to adjacency list.

    You may refer to the attachment for algorithm from adjacency list to adjacency matrix translation as a reference or guide.

    See the attached file.

    © BrainMass Inc. brainmass.com December 24, 2021, 8:50 pm ad1c9bdddf
    https://brainmass.com/computer-science/algorithms/adjacency-matrix-adjacency-list-translation-319184

    Attachments

    SOLUTION This solution is FREE courtesy of BrainMass!

    Considering that for graph G = (V, E), the node class of the adjacency list has following representation.

    class Node
    {
    Vertex element;
    Node next;
    }

    Node [] Translate_AdjacencyMatrix_to_AdjacencyList (boolean [][] M, int n)
    {
    Node [] AdjList = new Node[n];

    // Initialization of Adjacency List
    for i = 1 to n do
    AdjList[i] = null;

    // Construction of Adjacency List from Adjacency Matrix
    for i = 1 to n do
    for j = n to 1 do
    {
    if (M[i][j] == true)
    {
    Node P = new Node;
    P.next = AdjList[i];
    P.element = j;
    AdjList[i] = P;
    }
    }

    return (AdjList);
    }

    Notice that it is small modification of algorithm to convert Adjacency List to Adjacency Matrix.

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    © BrainMass Inc. brainmass.com December 24, 2021, 8:50 pm ad1c9bdddf>
    https://brainmass.com/computer-science/algorithms/adjacency-matrix-adjacency-list-translation-319184

    ADVERTISEMENT