📄 page561.html
字号:
<HTML><HEAD><TITLE>Testing Strong Connectedness</TITLE></HEAD><BODY bgcolor="#FFFFFF"> <a href="../index.html" target="_top"><img src="../icons/usins.gif" alt="Logo" align=right></a><b>Data Structures and Algorithms with Object-Oriented Design Patterns in Python</b><br><A NAME="tex2html7608" HREF="page562.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html7606" HREF="page558.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html7600" HREF="page560.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html7610" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H3><A NAME="SECTION0016343000000000000000">Testing Strong Connectedness</A></H3><P>A traversal of a directed graph (either depth-first or breadth-first)starting from a given vertexwill only visit all the vertices of an undirected graphif there is a path from the start vertex to every other vertex.Therefore,a simple way to test whether a directed graph is strongly connecteduses <IMG WIDTH=18 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline70975" SRC="img2249.gif" > traversals--one starting from each vertex in <IMG WIDTH=11 HEIGHT=12 ALIGN=BOTTOM ALT="tex2html_wrap_inline70551" SRC="img2167.gif" >.Each time the number of vertices visited is counted.The graph is strongly connected if all the vertices are visitedin each traversal.<P>Program <A HREF="page561.html#progdigraphc"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> shows how this can be implemented.It shows the<tt>getIsStronglyConnected</tt> method of the abstract <tt>Digraph</tt> classwhich returns the <tt>bool</tt> value <tt>True</tt> if the graphis <em>strongly</em> connected.<P><P><A NAME="51177"> </A><A NAME="progdigraphc"> </A> <IMG WIDTH=575 HEIGHT=218 ALIGN=BOTTOM ALT="program51130" SRC="img2324.gif" ><BR><STRONG>Program:</STRONG> Abstract <tt>Digraph</tt> class <tt>getIsConnected</tt> method.<BR><P><P>The accessor consists of a loop over all the vertices of the graph.Each iteration does a <tt>depthFirstTraversal</tt> usinga visitor that counts the number of vertices it visits.The running time for one iterationis essentially that of the <tt>depthFirstTraversal</tt>since <IMG WIDTH=108 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline60707" SRC="img668.gif" > for the counting visitor.Therefore, the worst-case running time for the <tt>getIsConnected</tt> methodis <IMG WIDTH=50 HEIGHT=28 ALIGN=MIDDLE ALT="tex2html_wrap_inline71371" SRC="img2325.gif" > when adjacency matrices are usedand <IMG WIDTH=119 HEIGHT=28 ALIGN=MIDDLE ALT="tex2html_wrap_inline71373" SRC="img2326.gif" >when adjacency lists are used to represent the graph.<P><HR><A NAME="tex2html7608" HREF="page562.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html7606" HREF="page558.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html7600" HREF="page560.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html7610" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <P><ADDRESS><img src="../icons/bruno.gif" alt="Bruno" align=right><a href="../copyright.html">Copyright © 2003</a> by <a href="../signature.html">Bruno R. Preiss, P.Eng.</a> All rights reserved.</ADDRESS></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -