C language algorithm 1.4: an improved version of the advanced improved version of the connectivity problem [video analysis]

Note: This article is an improved version of the previous article "C Language Algorithm 1.3: Advanced Improved Version of Connectivity Problem [Video Analysis]" , it is recommended to read the previous article before reading this article.

! ! ! Friends who like to watch videos, please click here (there is a comparison summary of 4 versions inside)! ! !

1. Source

Program 1.4 from the book "Algorithms: Implementation in C (Parts 1-4) 3rd Edition".


Second, the difference between the two versions

In version 1.3, if the two nodes are already connected, no processing will be done.
In version 1.4, if the two nodes are already connected, processing will still be done to reduce the depth of the tree, so that the number of searches to find the root node will be reduced.

3. Performance test results

Number of nodes Version 1.3 takes time (milliseconds) Version 1.4 takes time (milliseconds) time-consuming ratio
1000000 32 19 1.68
10 million 257 134 1.91
  1. The higher the number of nodes, the higher the performance improvement.
  2. The upper limit of the boost is 2 times.

4. Source code

There are many source files, so I won’t post them in the article. The links are here: github , gitee


5. Schematic diagram of the process

insert image description here


end of text

Guess you like

Origin blog.csdn.net/h837087787/article/details/122266063