ADS
Algorithms and Data Structures
Loading...
Searching...
No Matches
IncidenceGraph.h File Reference

The oriented graph on its matrix of incidence, exercise 12.2 of Morin's book, beyond the book: the \( n \times m \) matrix \( A \) with \( A_{i,j} = -1 \) if the node \( i \) is the source of the edge \( j \), \( +1 \) if it is its target, and 0 otherwise, a GRAPH [see Graph.h] whose nodes are \( 0 , \ldots , n - 1 \), on which the visits of Visit.h run as on the others. More...

#include "ADS/Contract.h"
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <vector>
#include "ADS/graph/impl/IncidenceGraph.tpp"

Go to the source code of this file.

Classes

class  ADS::IncidenceGraph
 an oriented graph on its matrix of incidence, kept by columns More...

Namespaces

namespace  ADS

Detailed description

The oriented graph on its matrix of incidence, exercise 12.2 of Morin's book, beyond the book: the \( n \times m \) matrix \( A \) with \( A_{i,j} = -1 \) if the node \( i \) is the source of the edge \( j \), \( +1 \) if it is its target, and 0 otherwise, a GRAPH [see Graph.h] whose nodes are \( 0 , \ldots , n - 1 \), on which the visits of Visit.h run as on the others.

The matrix is kept by columns, one column of \( n \) bytes per edge, so that the space is \( n m \) bytes, \( \Theta( n m ) \), more than the \( \Theta( n^2 ) \) of the adjacency matrix as soon as \( m > n \), and the costs of the operations of Morin's interface are

  • insertEdge( i , j ), the addEdge() of the book: a new column at the end, \( O( n ) \) amortized;
  • hasEdge( i , j ): the row \( i \), one entry per column, and the entry \( j \) of each column whose entry \( i \) is \( -1 \), \( O( m ) \);
  • deleteEdge( i , j ), the removeEdge() of the book: the column found as by hasEdge(), and the last column copied in its place, \( O( m + n ) \);
  • adj( i ), the outEdges() of the book: the row \( i \), and for each \( -1 \) the column searched for its \( +1 \), \( O( m + n \deg^+( i ) ) \), and inAdj( i ), the inEdges(), \( O( m + n \deg^-( i ) ) \);

so that no operation is faster than on the adjacency matrix or on the lists, and the matrix of incidence is a representation for the algebra of the graph (its rank, its cycles and cuts, the flows as the solutions of \( A x = b \) [see incidence() in Graph.h]), not for its visits. A loop has no column (its \( -1 \) and \( +1 \) would be in the same place), and two parallel edges have two equal columns.

The contracts [see Contract.h]: the nodes are in \( [ 0 , n ) \), an edge joins two distinct nodes; the invariant (one \( -1 \) and one \( +1 \) per column) is checked on the columns that an operation writes. The operations are defined in IncidenceGraph.tpp.

See also
P. Morin, Open Data Structures (in C++), Edition 0.1G, 2013, https://opendatastructures.org/ods-cpp.pdf, section 12.1 and exercise 12.2
Author
Donato Meoli
Dipartimento di Informatica
Università di Pisa