Adjacency Matrix to Adjacency List

PHOTO EMBED

Wed Jun 26 2024 14:55:27 GMT+0000 (Coordinated Universal Time)

Saved by @ayushg103 #c++

 vector<int> adjLs[V]; 
        
        // to change adjacency matrix to list 
        for(int i = 0;i<V;i++) {
            for(int j = 0;j<V;j++) {
                // self nodes are not considered
                if(adj[i][j] == 1 && i != j) {
                    adjLs[i].push_back(j); 
                    adjLs[j].push_back(i); 
                }
            }
        }
content_copyCOPY