开发三道工序课件_第1页
开发三道工序课件_第2页
开发三道工序课件_第3页
开发三道工序课件_第4页
开发三道工序课件_第5页
已阅读5页,还剩283页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1Chapter15

Graphs,Trees,andNetworks1Chapter15

Graphs,12Chap.1515.1UndirectedGraphs15.2DirectedGraphs15.3Trees15.4Networks15.5GraphAlgorithms

MinimumSpanningTreeShortestPath2Chap.1515.1UndirectedGraph23

Chap.15(Cont.)15.6NetworkClass開發三道工序:3Chap.15(Cont.)34Graphtheory圖論

FromWikipedia,thefreeencyclopediaInmathematicsandcomputerscience,graphtheoryisthestudyofgraphs,mathematicalstructuresusedtomodelpair-wiserelationsbetweenobjectsfromacertaincollection.

某collection的objects的兩兩關係4Graphtheory圖論

FromWikipedi45ApplicationsofGraphs

許多實際問題可用graph來表示。例如連接結構的一個網站,可以用有向圖(directedgraph):頂點(vertex)是網頁網址,如果有一個網頁B連結到網頁A,便有個連結(edge)在兩者A,B之間。

類似的,在travel問題,生物學,computerchip的設計,以及其他許多領域。開發algorithm來處理graph,因此主要應用是在computerscience。

graph可延伸為weighted

graph

(加權圖)。

例如,weight能夠代表連結(edge)的長度。5ApplicationsofGraphs5615.1UndirectedGraphs615.1UndirectedGraphs67 Example:

X

YZTAns:

5Vertices

6EdgesS7 Example:78Collection

ListSet

ArrayListLinkedListSortedSet

HashSetTreeSet88999101010111111S6NetworkClass開發三道工序:Alinkedlist!X某collection的objects的兩兩關係Performadepth-firstiterationfromS.Stack Vertexreturnedbynext()Z,T SHashSetTreeSetListSetxv5

GraphAlgorithms6ANetworkClass6ANetworkClassSqueue Vertexreturnedbynext()Z,T SV,T YYZ開發algorithm來處理graph,因此主要應用是在computerscience。12X

YZTX,Y,T,Z,Shaslength4.ShortestpathfromXtoS=?

Ans:2

SIngeneral,howcanthesmallestpath

between2verticesbedetermined?

Wewillcoverthat.S121213131314X

YZTX,Y,T,Z,Xisacycle.Y,T,S,Z,T,Yisnotacycle.(repeatededges:YTandTY)SIsY,Z,T,S,Z,X,Yacycle?

Yes!141415Collection

ListSet

ArrayListLinkedListSortedSet

HashSetTreeSetThisundirectedgraphisacyclic.15151616161717171815.2DirectedGraphs1815.2DirectedGraphs18191919202020212121222222X,Zthedirectionofthearrow.Graphtheory圖論

FromWikipedia,thefreeencyclopediaV,Zorderisunimportant:HashSetTreeSet6NetworkClass開發三道工序:5

GraphAlgorithmsAssumetheedgesareinsertedintothegraphasfollows:TNetworkClassS,T//SameasT,SCollectionPerformadepth-firstiterationfromS.YZStack Vertexreturnedbynext()YZ23X,Z23232415.3Trees2415.3Trees2425Collection

ListSet

ArrayListLinkedListSortedSet

HashSetTreeSet25252615.4Networks2615.4Networks262727272828282929293030303131313215.5

GraphAlgorithms3215.5

GraphAlgorithms3233333334343435

xvYZT

SAssumetheverticesareenteredinalphabeticalorder.Performabreadth-firstiterationfromS.

Ans:S,T,Z,Y,V,X

3535363636YZS,ZAcollectioninwhichForabreadth-firstiterationofadirectedgraph,orderisunimportant:Z,T SHashSetTreeSetYZListSet6NetworkClass開發三道工序:SAssumetheedgesareinsertedintothegraphasfollows:Assumetheedgesareinsertedintothegraphasfollows:orderisunimportant:ArrayListLinkedListSortedSetpriorityqueue(pq):<C,7><B,10>;remove<C,7>S,T(SameasT,S)Athealgorithmisthesame,but“neighbor”takesintoaccountS37Y3738383839393940X

V

YZTS404041Assumetheedgesareinsertedintothegraphasfollows:

S,T(SameasT,S)

S,Z

T,Y

T,Z

V,X

V,Z

X,Y

X,ZPerformabreadth-firstiterationfromS.41Assumetheedgesareinserte4142

queue

Vertexreturnedbynext()ST,Z SZ,Y TY,V,X ZV,X YX VXenqueuedequeue42queue Vertexreturnedby4243434344444445454546Forabreadth-firstiterationofadirected

graph,thealgorithmisthesame,but“neighbor”takesintoaccountthedirectionofthearrow.A

BCDStartingatA,theneighborsofAareBandC,butnotD.DNEVER

getsenqueued,andnevergetsreturnedbynext().46Forabreadth-firstiteratio46Y,V,T XXV,XV,X YT,YHashSetTreeSetCV,ZTHashSetTreeSetZ,Y TcheckC’sneighbors,find<B,9>;andaddittopq;5VerticesT,YCollection6ANetworkClassZ,T SAcollectioninwhich6NetworkClass開發三道工序:Performadepth-firstiterationfromS.HashSetTreeSet47Y,V,T X474748Collection

ListSet

ArrayListLinkedListSortedSet

HashSetTreeSet484849494950A

Stack!50AStack!5051X

V

YZTS515152Assumetheedgesareinsertedintothegraphasfollows:

S,T//SameasT,S

S,Z

T,Y

T,Z

V,X

V,Z

X,Y

X,ZPerformadepth-firstiterationfromS.52Assumetheedgesareinserte5253

Stack Vertexreturnedbynext()

S

Z,T

SX,V,T ZY,V,T X

V,T Y

TV TTopBottom53Stack Vertexreturnedby53545454555555565656orderisunimportant:T某collection的objects的兩兩關係X6NetworkClass開發三道工序:StartingatA,theneighborsofAareBandC,butnotD.ArrayListLinkedListSortedSetXGraphtheory圖論

FromWikipedia,thefreeencyclopedia2DirectedGraphs5

GraphAlgorithmsT,Z SYZS,ZPerformadepth-firstiterationfromS.CollectionX,Y,T,Z,Xisacycle.Trees,andBCDAssumetheedgesareinsertedintothegraphasfollows:YZ57orderisunimportant:57575858585959596060606161616262626363636464646565656666666767676868686969692DirectedGraphsV,T YV,XStack Vertexreturnedbynext()72Inmathematicsandcomputerscience,graphtheoryisthestudyofgraphs,mathematicalstructuresusedtomodelpair-wiserelationsbetweenobjectsfromacertaincollection.TArrayListLinkedListSortedSetArrayListLinkedListSortedSet某collection的objects的兩兩關係5

GraphAlgorithms5

GraphAlgorithmsthedirectionofthearrow.Assumetheedgesareinsertedintothegraphasfollows:6ANetworkClassAssumetheedgesareinsertedintothegraphasfollows:xvV,ZXVT702DirectedGraphs707071717172727273737374747475757576767677KeyIdea

C72A10B

priorityqueue(pq):<C,7><B,10>;remove

<C,7>checkC’sneighbors,find<B,9>;andaddittopq;markCthepredecessorofB

Now,pq:<B,9><B,10>77KeyIdea77787878797979808080818181828282838383848484858585868686878787888888898989Forabreadth-firstiterationofadirectedgraph,Performadepth-firstiterationfromS.Graphtheory圖論

FromWikipedia,thefreeencyclopediapriorityqueue(pq):<C,7><B,10>;remove<C,7>YZT,Z5GraphAlgorithmsThisundirectedgraphisacyclic.6NetworkClass開發三道工序:ArrayListLinkedListSortedSetNetworkClass許多實際問題可用graph來表示。YZCollectionYZYZIsY,Z,T,S,Z,X,Yacycle?Yes!Performabreadth-firstiterationfromS.ArrayListLinkedListSortedSet90Forabreadth-firstiteration909115.6ANetworkClass9115.6ANetworkClass9192929293939394NetworkClass94NetworkClass94959595969696979797989898999999100100100101101101102102102103103103104104104105105105106NetworkClass106NetworkClass106107107107108108108109109109110Acollectioninwhichorderisunimportant:Alinkedlist!

110Acollectioninwhich110111111111112112112113113113114114114115115115116116116117117117118118118119NetworkClass119NetworkClass119120120120121121121122122122123123123124124124125125125126126126127127127128128128129129129130130130131131131132132132133133133134134134135135135136136136137137137138138138139139139140140140141141141142142142143143143144144144145Chapter15

Graphs,Trees,andNetworks1Chapter15

Graphs,145146Chap.1515.1UndirectedGraphs15.2DirectedGraphs15.3Trees15.4Networks15.5GraphAlgorithms

MinimumSpanningTreeShortestPath2Chap.1515.1UndirectedGraph146147

Chap.15(Cont.)15.6NetworkClass開發三道工序:3Chap.15(Cont.)147148Graphtheory圖論

FromWikipedia,thefreeencyclopediaInmathematicsandcomputerscience,graphtheoryisthestudyofgraphs,mathematicalstructuresusedtomodelpair-wiserelationsbetweenobjectsfromacertaincollection.

某collection的objects的兩兩關係4Graphtheory圖論

FromWikipedi148149ApplicationsofGraphs

許多實際問題可用graph來表示。例如連接結構的一個網站,可以用有向圖(directedgraph):頂點(vertex)是網頁網址,如果有一個網頁B連結到網頁A,便有個連結(edge)在兩者A,B之間。

類似的,在travel問題,生物學,computerchip的設計,以及其他許多領域。開發algorithm來處理graph,因此主要應用是在computerscience。

graph可延伸為weighted

graph

(加權圖)。

例如,weight能夠代表連結(edge)的長度。5ApplicationsofGraphs14915015.1UndirectedGraphs615.1UndirectedGraphs150151 Example:

X

YZTAns:

5Vertices

6EdgesS7 Example:151152Collection

ListSet

ArrayListLinkedListSortedSet

HashSetTreeSet815215391531541015415511155S6NetworkClass開發三道工序:Alinkedlist!X某collection的objects的兩兩關係Performadepth-firstiterationfromS.Stack Vertexreturnedbynext()Z,T SHashSetTreeSetListSetxv5

GraphAlgorithms6ANetworkClass6ANetworkClassSqueue Vertexreturnedbynext()Z,T SV,T YYZ開發algorithm來處理graph,因此主要應用是在computerscience。156X

YZTX,Y,T,Z,Shaslength4.ShortestpathfromXtoS=?

Ans:2

SIngeneral,howcanthesmallestpath

between2verticesbedetermined?

Wewillcoverthat.S1215615713157158X

YZTX,Y,T,Z,Xisacycle.Y,T,S,Z,T,Yisnotacycle.(repeatededges:YTandTY)SIsY,Z,T,S,Z,X,Yacycle?

Yes!14158159Collection

ListSet

ArrayListLinkedListSortedSet

HashSetTreeSetThisundirectedgraphisacyclic.15159160161601611716116215.2DirectedGraphs1815.2DirectedGraphs16216319163164201641652116516622166X,Zthedirectionofthearrow.Graphtheory圖論

FromWikipedia,thefreeencyclopediaV,Zorderisunimportant:HashSetTreeSet6NetworkClass開發三道工序:5

GraphAlgorithmsAssumetheedgesareinsertedintothegraphasfollows:TNetworkClassS,T//SameasT,SCollectionPerformadepth-firstiterationfromS.YZStack Vertexreturnedbynext()YZ167X,Z2316716815.3Trees2415.3Trees168169Collection

ListSet

ArrayListLinkedListSortedSet

HashSetTreeSet2516917015.4Networks2615.4Networks170171271711722817217329173174301741753117517615.5

GraphAlgorithms3215.5

GraphAlgorithms1761773317717834178179

xvYZT

SAssumetheverticesareenteredinalphabeticalorder.Performabreadth-firstiterationfromS.

Ans:S,T,Z,Y,V,X

3517918036180YZS,ZAcollectioninwhichForabreadth-firstiterationofadirectedgraph,orderisunimportant:Z,T SHashSetTreeSetYZListSet6NetworkClass開發三道工序:SAssumetheedgesareinsertedintothegraphasfollows:Assumetheedgesareinsertedintothegraphasfollows:orderisunimportant:ArrayListLinkedListSortedSetpriorityqueue(pq):<C,7><B,10>;remove<C,7>S,T(SameasT,S)Athealgorithmisthesame,but“neighbor”takesintoaccountS181Y1811823818218339183184X

V

YZTS40184185Assumetheedgesareinsertedintothegraphasfollows:

S,T(SameasT,S)

S,Z

T,Y

T,Z

V,X

V,Z

X,Y

X,ZPerformabreadth-firstiterationfromS.41Assumetheedgesareinserte185186

queue

Vertexreturnedbynext()ST,Z SZ,Y TY,V,X ZV,X YX VXenqueuedequeue42queue Vertexreturnedby186187431871884418818945189190Forabreadth-firstiterationofadirected

graph,thealgorithmisthesame,but“neighbor”takesintoaccountthedirectionofthearrow.A

BCDStartingatA,theneighborsofAareBandC,butnotD.DNEVER

getsenqueued,andnevergetsreturnedbynext().46Forabreadth-firstiteratio190Y,V,T XXV,XV,X YT,YHashSetTreeSetCV,ZTHashSetTreeSetZ,Y TcheckC’sneighbors,find<B,9>;andaddittopq;5VerticesT,YCollection6ANetworkClassZ,T SAcollectioninwhich6NetworkClass開發三道工序:Performadepth-firstiterationfromS.HashSetTreeSet191Y,V,T X47191192Collection

ListSet

ArrayListLinkedListSortedSet

HashSetTreeSet4819219349193194A

Stack!50AStack!194195X

V

YZTS51195196Assumetheedgesareinsertedintothegraphasfollows:

S,T//SameasT,S

S,Z

T,Y

T,Z

V,X

V,Z

X,Y

X,ZPerformadepth-firstiterationfromS.52Assumetheedgesareinserte196197

Stack Vertexreturnedbynext()

S

Z,T

SX,V,T ZY,V,T X

V,T Y

TV TTopBottom53Stack Vertexreturnedby197198541981995519920056200orderisunimportant:T某collection的objects的兩兩關係X6NetworkClass開發三道工序:StartingatA,theneighborsofAareBandC,butnotD.ArrayListLinkedListSortedSetXGraphtheory圖論

FromWikipedia,thefreeencyclopedia2DirectedGraphs5

GraphAlgorithmsT,Z SYZS,ZPerformadepth-firstiterationfromS.CollectionX,Y,T,Z,Xisacycle.Trees,andBCDAssumetheedgesareinsertedintothegraphasfollows:YZ201orderisunimportant:572012025820220359203204602042056120520662206207632072086420820965209210662102116721121268212213692132DirectedGraphsV,T YV,XStack Vertexreturnedbynext()72Inmathematicsandcomputerscience,graphtheoryisthestudyofgraphs,mathematicalstructuresusedtomodelpair-wiserelationsbetweenobjectsfromacertaincollection.TArrayListLinkedList

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论