Talk C Chestnut Bar (43rd: Example of C language--figure)

Source: Internet
Author: User


Ladies and gentlemen, crossing, the last time we talked about the Huffman code example, this time we say the example is: figure. Gossip Hugh,

Words return to the positive turn. Let's talk C chestnuts together!


Crossing, referring to the picture, you may think of a variety of treasure map, haha. But the picture we're talking about is not a treasure map, it's a store of numbers

Data Structures . Take a daily example: the Spring Festival home, to travel through several provinces and cities to get home, then need to choose the way home

Line, so the provinces and cities on the way home as a junction, from one province to another city and city path as a line. It makes a home.

Figure. So it might be more abstract, and we'll illustrate it graphically, see:



If we are in city a, home in the city F, from a to f on the way there are City b,c,d,e. Between the two points there is a connection between the two

There is a train between the cities. Then you can see: There are three ways to go home:


A-c-f        //Through the city, the way home recently a-c-d-f//      from the city C to F ticket is not good to buy, need to detour to the city D, then can go home a-b-e-f      //Through the city more, and the road farthest. The road is high-speed rail, although the road is far, but it may be faster

Everybody, through this diagram, I think we all understand the abstract concept of the figure.


Next we'll talk about storing the diagram in your code. We can have two-dimensional array to hold the graph , the number of rows and columns of the two-dimensional array is the midpoint of the graph

Number, if there is a path between two points, a and a, then the value of row B in the two-dimensional array is set to 1, and if no path is set to 0. This

A two-dimensional array of storage graphs is called an adjacency matrix . The following is an example of the adjacency matrix of the diagram, in order to facilitate observation, I put the name of the row to make

Named after the point, and the value of 0 is not written.




The adjacency matrix can easily represent the diagram, but it also has some shortcomings, we look at the adjacency matrix above, there is a side of the figure in the

There is a value in the adjacency matrix, where the infinity in the graph has no value in the adjacency matrix, which results in a lot of whitespace in the adjacency matrix. "This

A lot of blank not to use, is really a waste of ah, this crossing said too right ah, this is the disadvantage of the adjacency matrix : It will waste a certain amount of storage

Storage space, and is more pronounced when the number of edges in the graph is small.


Everybody crossing, here's an example of the picture we're talking about here. I want to know what the following example, and listen to tell.


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

Talk C Chestnut Bar (43rd: Example of C language--figure)

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.