1 / 8

第七章习题

第七章习题. 习题集: 写出 7.3 所给图的深度优先和广度优先遍历序列 7.7 7.9,7.11 已知一个无向图用邻接矩阵存储,写出实现以下操作的算法: DeleteVex(&G,v) InsertArc(&G,v,w) 对操作的具体定义见教材 P157 。. 写出 7.3 所给图的深度优先和广度优先遍历序列. 深度优先顶点序列: 1 , 5 , 6 , 4 , 3 , 2 深度优先边序列: 1-5 , 5-6 , 6-4 , 4-3 , 3-2 广度优先顶点序列: 1 , 5 , 6 , 3 , 2 , 4

noreen
Download Presentation

第七章习题

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 第七章习题 • 习题集: • 写出7.3所给图的深度优先和广度优先遍历序列 • 7.7 • 7.9,7.11 • 已知一个无向图用邻接矩阵存储,写出实现以下操作的算法: • DeleteVex(&G,v) • InsertArc(&G,v,w) • 对操作的具体定义见教材P157。

  2. 写出7.3所给图的深度优先和广度优先遍历序列 深度优先顶点序列:1,5,6,4,3,2 深度优先边序列:1-5,5-6,6-4,4-3,3-2 广度优先顶点序列:1,5,6,3,2,4 广度优先边序列:1-5,1-6,1-3,1-2,5-4 1 5 2 4 6 3

  3. 7.7 邻接矩阵,Prim算法 e 3 9 b f 7 4 5 6 2 a 5 d 5 5 g 3 4 c 6 h 5

  4. 邻接表,Kruskal算法 …… e 3 9 b f 7 4 5 6 2 a 5 d 5 5 g 3 4 c 6 h 5

  5. 7.9 拓扑序列 1 2 3 5 4 6 1,5,2,3,6,4 1,5,2,6,3,4 1,5,6,2,3,4 5,1,2,3,6,4 5,1,2,6,3,4 5,1,6,2,3,4 5,6,1,2,3,4

  6. 无向图用邻接矩阵 Status InsertArc(MGraph &G,VertexType v,VertexType w) { //初始条件,G存在,v和w是G中的顶点 //操作结果:在图G中增加一条边 i=LocateVex(G,v); j=LocateVex(G,w); //定位 if(i<0||j<0) return ERROR; G.arcnum++; //边数加1 G.arcs[i][j].adj=1; G.arcs[j][i].adj=1 //将矩阵对应值置1 return OK; }

  7. Status DeleteVex(MGraph &G,VertexType v) {//初始条件,G存在,v是G中的顶点 //操作结果:删除图G中的顶点v及相关的边 k=LocateVex(G,v); //定位 if(k<0) return ERROR; for(i=0;i<G.vexnum;i++) //修改边数 if(G.arcs[i][k].adj) G.arcnum--;

  8. for(i=k+1;i<G.vexnum;i++) //v点后的顶点元素依次前移 G.vexs[i-1]=G.vexs[i]; for(i=0;i<G.vexnum;i++) //边矩阵v点后的各列前移 for(j=k+1;j<G.vexnum;j++) G.arcs[i][j-1] .adj=G.arcs[i][j] .adj; for(i=0;i<G.vexnum;i++) //边矩阵v点后的各行前移 for(j=k+1;j<G.vexnum;j++) G.arcs[j-1][i] .adj =G.arcs[j][i] .adj; // G.vexnum- -; //修改顶点数 return OK; }

More Related