Basic knowledge of graphs

Source: Internet
Author: User

One: the definition of a diagram

One figure g= ( v,e ) set by fixed point v and Edge set e v,w ", where v,w v v,w neighbor Then and only if ( v,w e

A path to a graph is a sequence of verticesW1,W2,W3~wn, Making (Wi,wi+1) belongs toE, so that the length of a path is the number of sides on that path, which equalsN-1.. From a vertex to itself can be thought of as a path, if the path does not contain edges, then the path length is0, which is a convenient way to define special cases. If the graph contains an edge from one vertex to its own (v,w), then the pathv,walso called a ring. The diagrams discussed for them are generally non-circular.

A simple path is this: all vertices on it are different, but the first vertex and the last vertex may be the same.

If there is a path from each vertex to each of the other vertices in an out-of-direction graph, it is said to be together. An undirected graph of this nature is called strong-connected. If a directed graph is not strongly connected, but its underlying diagram, that is, the graph formed by the direction of the arc being removed is connected, then the directed graph is called weakly connected. A full graph is a graph with one edge between each pair of vertices.

Two: the representation of graphs

We will consider the graph of the direction (the non-graph can be similar to the representation)

A simple way to represent graphs is to use two-dimensional arrays, called adjacency matrix representations. For each edge (u,v), we set a[u][v]=1, Otherwise the array element is set to 0, that is, if the edge exists is 1 , does not exist is 0 , if you have the right

Assign the right to A[u][v]. Instead, use a large or small weight as a token to represent a nonexistent edge.

Adjacency matrix method is very simple, but its shortcomings are also very obvious, if a graph of the side is not much, it is too wasted space, because the matrix required space is n^2. If the edges of the graphs are more, then this is the appropriate method.

If the graphs are sparse, a better approach is to use adjacency tables to represent them. For each vertex, we use a table to hold all the contiguous vertices. Arrays are usually replaced by lists that are inconvenient.

adjacency tables are the standard way to represent graphs, and each edge appears in two tables, so the use of this space is doubled.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Basic knowledge of graphs

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.