Algorithmic Solutions > LEDA > LEDA Guide > Graphs and Related Data Types > Associate Information with Graphs

Associate Information with Graphs

Motivation: It is often useful to associate information with nodes, edges, or faces of graphs.If your graph represents, for example, cities and distances between cities, you may want to associate the name of the city with the node that represents it and the distance between two cities with the corresponding edge.

LEDA provides the following means to associate information with nodes, edges, and faces of graphs. The information can be of a LEDA data type or a user defined data type.

Parameterized Graph Data Types

A Special Constructor for Graphs

The constructor G(int n_slots,int e_slots) of graphs allows to associate more than one piece of information with the nodes and edges of a graph.

Specialized Data Types to associate information with graphs

It is, of course, also possible to use general Advanced Data Types, like Maps, Dictionaries, and so on, for this purpose, but this is not recommended for efficiency reasons.

Tips

  • Use the parameterized graph data types if the information is an essential part of the graph.
  • Use arrays to associate information temporarily if almost all vertices, edges, faces are assigned information.
  • Use maps if only a fraction needs an entry.
  • Use the special constructor if speed is of utmost importance and the node/edge information is accessed many times in random order.

See also:

Graphs and Related Data Types


Manual Entries:

User Defined Parameter Types




Please send any suggestions, comments or questions to leda@algorithmic-solutions.com
© Copyright 2001-2003, Algorithmic Solutions Software GmbH