09.02.2015 Views

Sage Reference Manual: Graph Theory - Mirrors

Sage Reference Manual: Graph Theory - Mirrors

Sage Reference Manual: Graph Theory - Mirrors

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Sage</strong> <strong>Reference</strong> <strong>Manual</strong>: <strong>Graph</strong> <strong>Theory</strong>, Release 6.1.1<br />

•vertices - If vertices is a single vertex, returns the number of neighbors of vertex. If vertices is an<br />

iterable container of vertices, returns a list of degrees. If vertices is None, same as listing all vertices.<br />

•labels - see OUTPUT<br />

OUTPUT: Single vertex- an integer. Multiple vertices- a list of integers. If labels is True, then returns a<br />

dictionary mapping each vertex to its degree.<br />

EXAMPLES:<br />

sage: P = graphs.Petersen<strong>Graph</strong>()<br />

sage: P.degree(5)<br />

3<br />

sage: K = graphs.Complete<strong>Graph</strong>(9)<br />

sage: K.degree()<br />

[8, 8, 8, 8, 8, 8, 8, 8, 8]<br />

sage: D = Di<strong>Graph</strong>( { 0: [1,2,3], 1: [0,2], 2: [3], 3: [4], 4: [0,5], 5: [1] } )<br />

sage: D.degree(vertices = [0,1,2], labels=True)<br />

{0: 5, 1: 4, 2: 3}<br />

sage: D.degree()<br />

[5, 4, 3, 3, 3, 2]<br />

degree_histogram()<br />

Returns a list, whose ith entry is the frequency of degree i.<br />

EXAMPLES:<br />

sage: G = graphs.Grid2d<strong>Graph</strong>(9,12)<br />

sage: G.degree_histogram()<br />

[0, 0, 4, 34, 70]<br />

sage: G = graphs.Grid2d<strong>Graph</strong>(9,12).to_directed()<br />

sage: G.degree_histogram()<br />

[0, 0, 0, 0, 4, 0, 34, 0, 70]<br />

degree_iterator(vertices=None, labels=False)<br />

Returns an iterator over the degrees of the (di)graph.<br />

In the case of a digraph, the degree is defined as the sum of the in-degree and the out-degree, i.e. the total<br />

number of edges incident to a given vertex.<br />

INPUT:<br />

•labels (boolean) – if set to False (default) the method returns an iterator over degrees. Otherwise<br />

it returns an iterator over tuples (vertex, degree).<br />

•vertices - if specified, restrict to this subset.<br />

EXAMPLES:<br />

sage: G = graphs.Grid2d<strong>Graph</strong>(3,4)<br />

sage: for i in G.degree_iterator():<br />

... print i<br />

3<br />

4<br />

2<br />

...<br />

2<br />

4<br />

sage: for i in G.degree_iterator(labels=True):<br />

1.1. Generic graphs 35

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!