Docsity

Adjacency List method for Storing a Graph | CS 5050, Study notes of Algorithms and Programming

Toggle sidebar
bg1
Adjacency List method for storing a graph
final static int BAD=0;
final static int TREE=1;
class Node {
int ID;
int dfsNum;
boolean visited;
String nodeLabel;
EdgeList adj; // pointer to head of linked list of successors
public String toString()
{
return ID + nodeLabel ;
}
}
class EdgeList
{
EdgeList next;
Edge e;
}
class Edge {
int from; // endpoint of start node
int to; // endpoint of end node
double len; // length of edge in graph (or cost or other annotation)
int edgeType: {TREE BAD}
Edge(int f, int t, double l)
{ from = f; to = t; len =l;}
}
public class Graph{
final static int SIZE = 20;
Node [] nodes = new Node[SIZE];
}
Write code for doing a depth first search. Assume the nodes are
already stored in the graph.
(1) Label all nodes with dfs number (in sequential order)
(2) Label all edges with the type of edge it is๎˜ƒ

Partial preview of the text

Download Adjacency List method for Storing a Graph | CS 5050 and more Study notes Algorithms and Programming in PDF only on Docsity!

Adjacency List method for storing a graph

final static int BAD=0; final static int TREE=1;

class Node { int ID; int dfsNum; boolean visited; String nodeLabel; EdgeList adj; // pointer to head of linked list of successors public String toString() { return ID + nodeLabel ; } } class EdgeList { EdgeList next; Edge e; }

class Edge { int from; // endpoint of start node int to; // endpoint of end node double len; // length of edge in graph (or cost or other annotation) int edgeType: {TREE BAD} Edge( int f, int t, double l) { from = f; to = t; len =l;}

public class Graph{

final static int SIZE = 20; Node [] nodes = new Node[ SIZE ];

Write code for doing a depth first search. Assume the nodes are

already stored in the graph.

(1) Label all nodes with dfs number (in sequential order)

(2) Label all edges with the type of edge it is