Graph Traversal
Here is your task:
- Create a graph with 30 nodes ( => connectivity matrix). Since the connectivity matrix is empty (zeros everywhere), you have
a maximally disconnected graph: all nodes are single nodes.
- While the graph is disconnected, add single random bidirectional connections.
- Print the connectivity matrix (good old ASCII style, 30 rows, 30 columns), for every connection, print the depth
relative to node one. This means: instead of printing '1' for 'connected', print the depth value.
You are at the end of the semester now, you are therefore experienced and grown up JAVA programmers!
I therefore won't give any further hints, except if required (come to my office / email for help).
Ok, a little help. You need a method to traverse the graph. Start from node one, and mark every node (keep an array
for the nodes) which was visited. After traversal, check the array: if not all nodes are marked, your graph is still disconnected.
Bonus (4 points):
Visualize the resulting graph as a circle of 30 nodes, with edges between connected nodes.
Bonus (another 2 points):
Same as above, but show the graph each time a single connection was created (and pause for 100 milli seconds).
Bonus (another 5 points):
Program an ANIMATED little box that travels (depth first)the graph along the edges.
Visited nodes should get a different color.
Due date: Sunday, May 2