📄 page253.html
字号:
<HTML><HEAD><TITLE>Terminology</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="tex2html4118" HREF="page254.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html4116" HREF="page252.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html4110" HREF="page252.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html4120" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H3><A NAME="SECTION009101000000000000000">Terminology</A></H3><P>Consider a tree <IMG WIDTH=155 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline62773" SRC="img1041.gif" >, <IMG WIDTH=39 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline58503" SRC="img238.gif" >,as given by Definition <A HREF="page252.html#defntree"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.<UL><LI> The <em>degree</em> of a node is the number of subtrees associated with that node. For example, the degree of tree <I>T</I> is <I>n</I>.<LI> A node of degree zero has no subtrees. Such a node is called a <em>leaf</em><A NAME=14451> </A>.<LI> Each root <IMG WIDTH=11 HEIGHT=14 ALIGN=MIDDLE ALT="tex2html_wrap_inline62821" SRC="img1050.gif" > of subtree <IMG WIDTH=14 HEIGHT=22 ALIGN=MIDDLE ALT="tex2html_wrap_inline62823" SRC="img1051.gif" > of tree <I>T</I> is called a <em>child</em><A NAME=14453> </A> of <I>r</I>. The term <em>grandchild</em> is defined in a similar manner.<LI> The root node <I>r</I> of tree <I>T</I> is the <em>parent</em><A NAME=14456> </A> of all the roots <IMG WIDTH=11 HEIGHT=14 ALIGN=MIDDLE ALT="tex2html_wrap_inline62821" SRC="img1050.gif" > of the subtrees <IMG WIDTH=14 HEIGHT=22 ALIGN=MIDDLE ALT="tex2html_wrap_inline62823" SRC="img1051.gif" >, <IMG WIDTH=64 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline62837" SRC="img1052.gif" >. The term <em>grandparent</em> is defined in a similar manner.<LI> Two roots <IMG WIDTH=11 HEIGHT=14 ALIGN=MIDDLE ALT="tex2html_wrap_inline62821" SRC="img1050.gif" > and <IMG WIDTH=13 HEIGHT=15 ALIGN=MIDDLE ALT="tex2html_wrap_inline62841" SRC="img1053.gif" > of distinct subtrees <IMG WIDTH=14 HEIGHT=22 ALIGN=MIDDLE ALT="tex2html_wrap_inline62823" SRC="img1051.gif" > and <IMG WIDTH=14 HEIGHT=23 ALIGN=MIDDLE ALT="tex2html_wrap_inline62845" SRC="img1054.gif" > of tree <I>T</I> are called <em>siblings</em><A NAME=14459> </A>.</UL><P>Clearly the terminology used for describing tree data structuresis a curious mixture of mathematics, genealogy, and botany.There is still more terminology to be introduced,but in order to do that, we need the following definition:<P><BLOCKQUOTE> <b>Definition (Path and Path Length)</b><A NAME="defnpath"> </A>Given a tree <I>T</I> containing the set of nodes <I>R</I>,a <em>path</em> in <I>T</I> is defined as a non-empty sequence of nodes<P> <IMG WIDTH=320 HEIGHT=16 ALIGN=BOTTOM ALT="displaymath62811" SRC="img1055.gif" ><P>where <IMG WIDTH=44 HEIGHT=22 ALIGN=MIDDLE ALT="tex2html_wrap_inline62855" SRC="img1056.gif" >, for <IMG WIDTH=63 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline62857" SRC="img1057.gif" >such that the <IMG WIDTH=17 HEIGHT=14 ALIGN=BOTTOM ALT="tex2html_wrap_inline57847" SRC="img77.gif" > node in the sequence, <IMG WIDTH=11 HEIGHT=14 ALIGN=MIDDLE ALT="tex2html_wrap_inline62821" SRC="img1050.gif" >,is the <em>parent</em> of the <IMG WIDTH=56 HEIGHT=28 ALIGN=MIDDLE ALT="tex2html_wrap_inline62863" SRC="img1058.gif" > node in the sequence <IMG WIDTH=27 HEIGHT=15 ALIGN=MIDDLE ALT="tex2html_wrap_inline62865" SRC="img1059.gif" >.The <em>length</em> of path <I>P</I> is <I>k</I>-1.</BLOCKQUOTE><P>For example, consider again the tree <IMG WIDTH=14 HEIGHT=22 ALIGN=MIDDLE ALT="tex2html_wrap_inline62791" SRC="img1048.gif" > shown in Figure <A HREF="page252.html#figtree1"><IMG ALIGN=BOTTOM ALT="gif" SRC="../icons/cross_ref_motif.gif"></A>.This tree contains many different paths.In fact, if you count carefully, you should find that there are exactly 29distinct paths in tree <IMG WIDTH=14 HEIGHT=22 ALIGN=MIDDLE ALT="tex2html_wrap_inline62791" SRC="img1048.gif" >.This includes the path of length zero, <IMG WIDTH=28 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline62875" SRC="img1060.gif" >;the path of length one, <IMG WIDTH=47 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline62877" SRC="img1061.gif" >;and the path of length three, <IMG WIDTH=85 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline62879" SRC="img1062.gif" >.<P><HR><A NAME="tex2html4118" HREF="page254.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html4116" HREF="page252.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html4110" HREF="page252.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A> <A NAME="tex2html4120" 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 + -