For each some Graph , may need to find out the "Minimum cost " way to build .
for this graph , Now need to find out the min-cost tree .
This method is named as
Kruskal
:
Now we get {v0,v1,v3,v4,v5,v6,v7,v8} 9 points .and if weconsider the value between each point standing for the cost ,now let's
make the costminimum and make it through.
Step 1:
get all edges and sort
7(v7,v4),8(v2,v8),10(v1,v0),11(v0,v5),12(v1,v8),16(v1,v6),
16(v3,v7),17(v6,v5),18(v2,v1),19(v6,v7),20(v3,v4),21(v8,v3),
22(v2,v3),26(v5,v4)
Step 2:
Now let's connect all points
by the order just sorted .
Note: before do this ,
prepare 9 Sets to store each point group.
In beginning , 9 Sets should be like :
{v0},{v1},{v2},{v3},{v4},{v5},{v6},{v7},{v8},{v9}
Now Do it .
Let's start with (v4,v7).
Sets(8 sets) :
{v0},{v1},{v2},{v3},{v4,v7},{v5},{v6},{v8}
(v2,v8)
Sets(7 sets):
{v0},{v1},{v2,v8},{v3},{v4,v7},{v5},{v6}
Continue , now (v1,v0)
Sets(6 sets):
{v0,v1},{v2,v8},{v3},{v4,v7},{v5},{v6}
all what we should remember is :
1.new added 2 points shall not be exist in the same set.
e.g. now I want to add {v2,v8}, whichis not allowed ,as they(v2,v8) are already in the same set.
2.Once we get only 1 set , we stop .
Now Let's continue.
Add (v0,v5)
Now Sets(5 sets):
{v0,v1,v5},{v2,v8},{v3},{v4,v7},{v6}
Add (v1,v8), As points already added, We just need to union these twosets.
Now Sets(4 sets):
{v0,v1,v5,v2,v8},{v3},{v4,v7},{v6}
Next ,Add(v1,v6)
Now Sets(3 SETS):
{v0,v1,v5,v2,v8,v6},{v3},{v4,v7}
Next (V3,V7)
Sets(2 SETS):
{v0,v1,v5,v2,v8,v6},{V3,v4,v7}
Next (v5,v6),Because these are in the same set already ,so jump to next directly.
Same reason for Next (V1,V2) ,These are in the same set.
Ok, Now (V6,V7)
Sets (1 set):
{v0,v1,v5,v2,v8,v6,V3,v4,v7}
Finish.
分享到:
相关推荐
perl programming code to generate the minimum spanning tree using kruskal
Generate POJO-JPA-Repository-Service
Generate POJO-JPA-Swagger-DTO
Generate POJO-JPA-PO
npm install generate-radix-tree 用法 const gentree = require ( 'generate-radix-tree' ) const match = gentree ( [ { match : 'hello' } , { match : 'world' } , { match : 'hello world' } ] ) console . ...
You need to generate a topology before evaluating the two schemes. You can use the topology generator that I introduced in www.sensor608.com/srnc.html. 3 System requirement This tool is developed ...
Generate Objective-C headers from Mach-O files.
npm install --save-dev generate-asset-webpack-plugin 用法 var GenerateAssetPlugin = require ( 'generate-asset-webpack-plugin' ) ; var webpackConfig = { plugins : [ new GenerateAssetPlugin ( { ...
采用RNN或者LSTM模型训练数据, 生成音乐序列 采用了keras框架,音乐数据读写采用了python的midi库 不加入Lsystem系统时, 可生成音乐序列 加入Lsystem, 生成和弦分解序列
An Appwizard to Generate Non-COM Projects that can use ATL Object Wizard使用ATL对象向导创建非COM工程
codegenerate-1.3.8-javadoccodegenerate-1.3.8-javadoccodegenerate-1.3.8-javadoccodegenerate-1.3.8-javadoccodegenerate-1.3.8-javadoccodegenerate-1.3.8-javadoccodegenerate-1.3.8-javadoccodegenerate-1.3.8...
python-generate-plc-program-main.zip
目录变更记录执照 安装使用NPM: $ npm install generate-api-key 使用纱线: $ yarn add generate-api-key 用法generate-api-key库可以通过利用几种生成方法(例如string , bytes , base32 , base62 , uuidv4和...
codegenerate-3.4.6.jar jar包
Generate a function or script file call tree and plot it in a figure
生成-google-calendar-link-bower 凉亭包。 凉亭包。 说明 发布一个 bower 包,因为不是导出依赖于库的 glabal 对象。 依赖的不公开全局对象。 使用转换并将其发布为 bower 包。... src/generate-google-c
python库,解压后可用。 资源全名:sqlite_generate-0.1-py3-none-any.whl
代码生成器,很好的例子,方便程序的开发
资源来自pypi官网。 资源全名:sqlite_generate-0.1-py3-none-any.whl
python库,解压后可用。 资源全名:django_sitemap_generate-0.0.2-py3-none-any.whl