graphscope.nx.generators.sudoku.sudoku_graph#

graphscope.nx.generators.sudoku.sudoku_graph(n=3)[source]#

Returns the n-Sudoku graph. The default value of n is 3.

The n-Sudoku graph is a graph with n^4 vertices, corresponding to the cells of an n^2 by n^2 grid. Two distinct vertices are adjacent if and only if they belong to the same row, column, or n-by-n box.

Parameters:

n (integer) – The order of the Sudoku graph, equal to the square root of the number of rows. The default is 3.

Returns:

The n-Sudoku graph Sud(n).

Return type:

NetworkX graph

Examples

>>> G = nx.sudoku_graph()
>>> G.number_of_nodes()
81
>>> G.number_of_edges()
810
>>> sorted(G.neighbors(42))
[6, 15, 24, 33, 34, 35, 36, 37, 38, 39, 40, 41, 43, 44, 51, 52, 53, 60, 69, 78]
>>> G = nx.sudoku_graph(2)
>>> G.number_of_nodes()
16
>>> G.number_of_edges()
56

References