page313.html
来自「Data Structures And Algorithms With Obje」· HTML 代码 · 共 54 行
HTML
54 行
<HTML><HEAD><TITLE>find Method</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="tex2html4809" HREF="page314.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html4807" HREF="page311.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html4801" HREF="page312.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html4811" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H3><A NAME="SECTION0010412000000000000000"><tt>find</tt> Method</A></H3><P>Program <A HREF="page313.html#progbinarySearchTreeb"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> gives the code for the <tt>find</tt> methodof the <tt>BinarySearchTree</tt> class.In addition to <tt>self</tt>,the <tt>find</tt> method takes as its argument an object.The purpose of the method is to search the tree for an object in the treethat matches the argument.If a match is found, <tt>find</tt> returns the matching object.Otherwise, <tt>find</tt> returns <tt>None</tt>.<P><P><A NAME="18796"> </A><A NAME="progbinarySearchTreeb"> </A> <IMG WIDTH=575 HEIGHT=428 ALIGN=BOTTOM ALT="program18679" SRC="img1235.gif" ><BR><STRONG>Program:</STRONG> <tt>BinarySearchTree</tt> class <tt>find</tt> and <tt>getMin</tt> methods.<BR><P><P>The recursive <tt>find</tt> method starts its search at the rootand descends one level in the tree for each recursive call.At each level at most one object comparison is made (line 6).The worst case running time for a search is<P> <IMG WIDTH=305 HEIGHT=16 ALIGN=BOTTOM ALT="displaymath64133" SRC="img1236.gif" ><P>where <IMG WIDTH=42 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline63515" SRC="img1154.gif" > is the time to compare two objectsand <I>n</I> is the number of internal nodes in the tree.The same asymptotic running time applies for both successfuland unsuccessful searches.<P>The average running time for a successful search is <IMG WIDTH=142 HEIGHT=30 ALIGN=MIDDLE ALT="tex2html_wrap_inline64139" SRC="img1237.gif" >,where <IMG WIDTH=154 HEIGHT=30 ALIGN=MIDDLE ALT="tex2html_wrap_inline64141" SRC="img1238.gif" > is the average depthof an internal node in a binary search tree.If <IMG WIDTH=96 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline64143" SRC="img1239.gif" >, the average time of a successful search is <IMG WIDTH=56 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline59347" SRC="img400.gif" >.<P>The average running time for an unsuccessful search is <IMG WIDTH=101 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline64147" SRC="img1240.gif" >,where <IMG WIDTH=151 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline64149" SRC="img1241.gif" > is the average depthof an external node in a binary search tree.If <IMG WIDTH=96 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline64143" SRC="img1239.gif" >, the average time of an unsuccessful search is <IMG WIDTH=56 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline59347" SRC="img400.gif" >.<P><HR><A NAME="tex2html4809" HREF="page314.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html4807" HREF="page311.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html4801" HREF="page312.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html4811" 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 + =
减小字号Ctrl + -
显示快捷键?