g=Graph()

//eg 1::

g = Graph({1:[2], 2:[3,8],3:[4,5],5:[6,7]});// plots a tree
g.plot() 

g.coloring()
[[2, 4, 5], [1, 3, 6, 7, 8]] // colors two adjacent nodes differently

g.chromatic_number()
 2 //output

//eg 2::

g = Graph({1:[2], 2:[3,8],3:[4,5,9],4:[11,12],5:[6,7,10]}); // plots a tree
g.plot()

g.coloring()
[[2, 4, 5, 9], [1, 3, 6, 7, 8, 10, 11, 12]] // colors two adjacent nodes differently

g.chromatic_number()
 2 //output

// It is showed that all the trees can be vertex colored with TWO colors

Kreyszig-21.8-18-U (last edited 2010-12-18 08:19:52 by koumudi)