Nermeen
Nermeen

Reputation: 11

How to make a graph for braedth first search algorithm

I'm new to use graphs in Java, but I have implemented a code that finds the routes between two nodes using breadth first search algorithm and I need to show the output on a graph, can anyone help me in doing so .

Upvotes: 0

Views: 54

Answers (1)

TangKe
TangKe

Reputation: 378

For a beginner, I would recommend two popular graph representations:

Adjacency Matrix: https://en.wikipedia.org/wiki/Adjacency_matrix

Adjacency List: https://en.wikipedia.org/wiki/Adjacency_list

To understand and practice Breadth-first search/Depth-first search, use Adjacency Matrix because neighbors are easier to access in this data structure. It is as simple as a 2-dimension array:

int[][] adj = new int[10][20];

Example from Princeton University: http://algs4.cs.princeton.edu/41graph/AdjMatrixGraph.java.html

Upvotes: 3

Related Questions