Graph Colorization????

Hi everyone,

I am working on a graph assignment where I have 10 nodes.
0,1,5.
1,0,2,4.
2,1,5,7.
3,4,6.
4,1,3,5,6,9.
5,0,2,4,8.
6,3,4,8.
7,2,8.
8,5,6,7,9.
9,4,8.



I need to come up with the code for colorizing the nodes with the minumum colors possible.

My logic algorithm is short, as I am stuck on how to come up with a solution.

My first idea is that I need a nested loop.

first loop goes through the Nodes and the second goes through the AdjacentNode.

But I cant figure out the algorithm for the inside the second loop.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Graph colorizeGraph(Graph graph, string* colors, int numColors)
   {
      GraphNode temp;

	 for(int i = 0; i < graph.getNumNodes(); i++)
	 {
		 // this hole part below is wrong
                 // only print the first 2 nodes(with color)
		 temp = graph.getNodeAt(i);
		 for (int j = 0; j<temp.getNumAdjacentNodes(); j++)
		 {
			temp.setColor(colors[i]);
			graph.setNodeAt(i, temp);
		 }
		 
	 }
     return graph;
   }


Any help is apreciated.

Thanks
Topic archived. No new replies allowed.