圖的深度優(yōu)先遍歷

上傳人:zhu****ei 文檔編號(hào):253249485 上傳時(shí)間:2024-12-10 格式:PPT 頁(yè)數(shù):54 大?。?.30MB
收藏 版權(quán)申訴 舉報(bào) 下載
圖的深度優(yōu)先遍歷_第1頁(yè)
第1頁(yè) / 共54頁(yè)
圖的深度優(yōu)先遍歷_第2頁(yè)
第2頁(yè) / 共54頁(yè)
圖的深度優(yōu)先遍歷_第3頁(yè)
第3頁(yè) / 共54頁(yè)

下載文檔到電腦,查找使用更方便

14.9 積分

下載資源

還剩頁(yè)未讀,繼續(xù)閱讀

資源描述:

《圖的深度優(yōu)先遍歷》由會(huì)員分享,可在線閱讀,更多相關(guān)《圖的深度優(yōu)先遍歷(54頁(yè)珍藏版)》請(qǐng)?jiān)谘b配圖網(wǎng)上搜索。

1、單擊此處編輯母版標(biāo)題樣式,,單擊此處編輯母版文本樣式,,第二級(jí),,第三級(jí),,第四級(jí),,第五級(jí),,,*,7.3圖的遍歷,,回顧其他數(shù)據(jù)結(jié)構(gòu)的遍歷:,,順序表的遍歷,,單鏈表的遍歷,,二叉樹(shù)的遍歷,,展望:,,那么對(duì)于圖,我們?cè)鯓舆M(jìn)行遍歷呢?,,圖的深度優(yōu)先遍歷,,圖的廣度優(yōu)先遍歷,,,這兩個(gè)算法是后面拓?fù)渑判?、求關(guān)鍵路徑算法的基礎(chǔ),,,7.3.1.連通圖的深度優(yōu)先遍歷,,,,1.深度優(yōu)先遍歷以v開(kāi)始的連通圖,訪問(wèn),v,,分別深度優(yōu)先遍歷,v,的各個(gè)未被訪問(wèn)的鄰接點(diǎn),算法描述:,,2.算法演示,,,0,,,1,v1,,2,v2,,3,V3,,4,V4,,5,v5,,6,v6,,7,v7,,8,v8

2、,,v2,,v3,,v1,,v4,,v5,,v1,,v6,,v7,,v2,,v8,,v2,,v8,,v3,,v7,,v3,,v6,,v4,,v5,,v1,v2,v3,v4,v5,v6,v7,v8,例圖及其鄰接表表示,,演示開(kāi)始,以v1為遍歷的起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,v8,v4,,,v5,v2,v8,,,v3,v1,v7,,,v6,v3,,,v7,v3,v6,,0,,,1,v1,,2,v2,,3,V3,,4,V4,,5,v5,,6,v6,,7,v7,,8,v8

23、,,v2,,v3,,v1,,v4,,v5,,v1,,v6,,v7,,v2,,v8,,v2,,v8,,v3,,v7,,v3,,v6,,v4,,v5,,,,v1,,,v2,v1,v5,,,v4,v2,,,v8,v4,,,v5,v2,v8,,,v3,v1,v7,,,v6,v3,,,v7,v3,v6,,0,,,1,v1,,2,v2,,3,V3,,4,V4,,5,v5,,6,v6,,7,v7,,8,v8,,v2,,v3,,v1,,v4,,v5,,v1,,v6,,v7,,v2,,v8,,v2,,v8,,v3,,v7,,v3,,v6,,v4,,v5,,,,v1,,,v2,v1,v5,,,v4,v2,,,v8

24、,v4,,,v5,v2,v8,,,v3,v1,v7,,,v6,v3,,,v7,v3,v6,,0,,,1,v1,,2,v2,,3,V3,,4,V4,,5,v5,,6,v6,,7,v7,,8,v8,,v2,,v3,,v1,,v4,,v5,,v1,,v6,,v7,,v2,,v8,,v2,,v8,,v3,,v7,,v3,,v6,,v4,,v5,,,,v1,,,v2,v1,v5,,,v4,v2,,,v8,v4,,,v5,v2,v8,,,v3,v1,v7,,,v6,v3,,,v7,v3,v6,,演示結(jié)束,,3.算法實(shí)現(xiàn),,從演示過(guò)程可以看出,我們必須知道頂點(diǎn)是否已經(jīng)被訪問(wèn)過(guò)。在具體實(shí)現(xiàn)時(shí),我們用一個(gè)全局?jǐn)?shù)

25、組visited[]來(lái)記錄頂點(diǎn)是否被訪問(wèn)過(guò)。如果visited[i]的值為T(mén)rue,則頂點(diǎn)vi已經(jīng)被訪問(wèn),否則沒(méi)有被訪問(wèn)。,,3.算法實(shí)現(xiàn),,Void DFS(Graph G,int v),,{,,Visited[v]=True;cout<

26、rue;//以前未被訪問(wèn),此處被訪問(wèn),,//改變對(duì)應(yīng)的標(biāo)志為已經(jīng)訪問(wèn),,cout<0;w=NextAdjVex(mg,v,w)),,{//對(duì)于v的每一個(gè)鄰接點(diǎn)進(jìn)行考察,,if(visited[w]==false)//當(dāng)該結(jié)點(diǎn)未被訪問(wèn)時(shí),,DFS(mg,w);//進(jìn)行深度優(yōu)先遍歷,,},,},,練習(xí)題:,,,對(duì)于下面一個(gè)圖及其存儲(chǔ)結(jié)構(gòu),寫(xiě)出以v2、v8為起始點(diǎn)的深度優(yōu)先遍歷序列。,,0,,,1,v1,,2,v2,,3,V3,,4,V4,,5,v5,,6,v6,,7,v7,

27、,8,v8,,v2,,v3,,v1,,v4,,v5,,v1,,v6,,v7,,v2,,v8,,v2,,v8,,v3,,v7,,v3,,v6,,v4,,v5,,v1,v2,v3,v4,v5,v6,v7,v8,例圖及其鄰接表表示,,,答案為:,,以v2為起始點(diǎn):v2-v1-v3-v6-v7-v4-v8-v5,,,以v8為起始點(diǎn):v8-v4-v2-v1-v3-v6-v7-v5,,思考題:,,若圖不是連通圖,如何進(jìn)行深度優(yōu)先遍歷?,,請(qǐng)建立下圖的鄰接表結(jié)構(gòu),并進(jìn)行深度優(yōu)先遍歷.,v1,v2,v3,v4,v5,v6,v7,,bool visited[100]={false};,,,void DFSTraverse(ALGraph mg),,{,,for(int i=1 ;i<=mg.vexnum;i++),,{,,if(visited[i]==false),,DFS(mg,i);,,},,},,

展開(kāi)閱讀全文
溫馨提示:
1: 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
2: 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
3.本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
5. 裝配圖網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

相關(guān)資源

更多
正為您匹配相似的精品文檔

相關(guān)搜索

關(guān)于我們 - 網(wǎng)站聲明 - 網(wǎng)站地圖 - 資源地圖 - 友情鏈接 - 網(wǎng)站客服 - 聯(lián)系我們

copyright@ 2023-2025  zhuangpeitu.com 裝配圖網(wǎng)版權(quán)所有   聯(lián)系電話:18123376007

備案號(hào):ICP2024067431號(hào)-1 川公網(wǎng)安備51140202000466號(hào)


本站為文檔C2C交易模式,即用戶上傳的文檔直接被用戶下載,本站只是中間服務(wù)平臺(tái),本站所有文檔下載所得的收益歸上傳人(含作者)所有。裝配圖網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)上載內(nèi)容本身不做任何修改或編輯。若文檔所含內(nèi)容侵犯了您的版權(quán)或隱私,請(qǐng)立即通知裝配圖網(wǎng),我們立即給予刪除!

五月丁香婷婷狠狠色,亚洲日韩欧美精品久久久不卡,欧美日韩国产黄片三级,手机在线观看成人国产亚洲