⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 page321.html

📁 Data Structures And Algorithms With Object-Oriented Design Patterns In Python (2003) source code and
💻 HTML
字号:
<HTML><HEAD><TITLE>Instance Attributes</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="tex2html4897" HREF="page322.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html4895" HREF="page320.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html4889" HREF="page320.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html4899" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H3><A NAME="SECTION0010511000000000000000">Instance Attributes</A></H3><P>Program&nbsp;<A HREF="page320.html#progavlTreea"><IMG  ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A> indicates thatan additional instance attribute is added in the <tt>AVLTree</tt> class.This turns out to be necessary because we need to be able todetermine quickly, i.e., in <I>O</I>(1) time,that the AVL balance condition is satisfied at a given node in the tree.In general, the running time required to compute the height of atree containing <I>n</I> nodes is <I>O</I>(<I>n</I>).Therefore, to determine whether the AVL balancecondition is satisfied at a given node, it is necessary to traverse completely the subtrees of the given node.But this cannot be done in constant time.<P>To make it possible to verify the AVL balance condition in constant time,the instance attribute <tt>_height</tt> has been added.Thus, every node in an <tt>AVLTree</tt> keeps track of its own height.In this way it is possible for the <tt>height</tt> propertyto run in constant time--all it needs to do is to return the value ofthe <tt>_height</tt> instance attribute.And this makes it possible to test whether the AVL balanced conditionsatisfied at a given node in constant time.<P><HR><A NAME="tex2html4897" HREF="page322.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html4895" HREF="page320.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html4889" HREF="page320.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html4899" 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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -