page568.html

来自「Data Structures And Algorithms With Obje」· HTML 代码 · 共 46 行

HTML
46
字号
<HTML><HEAD><TITLE>Running Time Analysis</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="tex2html7687" HREF="page569.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html7685" HREF="page564.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html7681" HREF="page567.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html7689" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H3><A NAME="SECTION0016414000000000000000">Running Time Analysis</A></H3><P>The running time of the <tt>DijkstrasAlgorithm</tt> methodis dominated by the running time of the main loop (lines&nbsp;11-23).(It is easy to see that lines&nbsp;4-10 and&nbsp;24-39 run in  <IMG WIDTH=43 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline70999" SRC="img2255.gif"  > time).<P>To determine the running time of the main loop,we proceed as follows:First, we ignore temporarily the time required for the <tt>enqueue</tt>and <tt>dequeue</tt> operations in the priority queue.Clearly, each vertex in the graph is processed exactly once.When a vertex is processed all the edges emanating from it are considered.Therefore, the time (ignoring the priority queue operations) takenis <I>O</I>(|<I>V</I>|+|<I>E</I>|) when adjacency lists are used and <IMG WIDTH=52 HEIGHT=28 ALIGN=MIDDLE ALT="tex2html_wrap_inline71851" SRC="img2372.gif"  > when adjacency matrices are used.<P>Now, we add back the worst-case time requiredfor the priority queue operations.In the worst case, a vertex is enqueued and subsequently dequeuedonce for every edge in the graph.Therefore, the length of the priority queue is at most  <IMG WIDTH=17 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline70987" SRC="img2251.gif"  >.As a result, the worst-case time for each operation is  <IMG WIDTH=65 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline71855" SRC="img2373.gif"  >.<P>Thus, the worst-case running time for Dijkstra's algorithm is<P> <IMG WIDTH=315 HEIGHT=16 ALIGN=BOTTOM ALT="displaymath71843" SRC="img2374.gif"  ><P>when adjacency lists are used, and<P> <IMG WIDTH=319 HEIGHT=19 ALIGN=BOTTOM ALT="displaymath71844" SRC="img2375.gif"  ><P>when adjacency matrices are used to represent the input graph.<P><HR><A NAME="tex2html7687" HREF="page569.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html7685" HREF="page564.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html7681" HREF="page567.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html7689" 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 &#169; 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 + =
减小字号Ctrl + -
显示快捷键?