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

📄 page393.html

📁 wqeqwvrw rkjqhwrjwq jkhrjqwhrwq jkhrwq
💻 HTML
字号:
<HTML>
<HEAD>
<TITLE>Comparing Sets</TITLE>
</HEAD>
<BODY bgcolor="#FFFFFF">
 <img src="cover75.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/cover75.gif" alt="Logo" align=right>
<b>Data Structures and Algorithms 
with Object-Oriented Design Patterns in C++</b><br>
<A NAME="tex2html6785" HREF="page394.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page394.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="next_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/next_motif.gif"></A> <A NAME="tex2html6783" HREF="page390.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page390.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="up_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/up_motif.gif"></A> <A NAME="tex2html6779" HREF="page392.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page392.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="previous_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/previous_motif.gif"></A> <A NAME="tex2html6787" HREF="page9.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page9.html"><IMG WIDTH=65 HEIGHT=24 ALIGN=BOTTOM ALT="contents" SRC="contents_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/contents_motif.gif"></A> <A NAME="tex2html6788" HREF="page620.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page620.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="index_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/index_motif.gif"></A> <BR><HR>
<H3><A NAME="SECTION0013203000000000000000">Comparing Sets</A></H3>
<P>
There is a special family of operators for comparing sets.
Consider two sets, say <I>S</I> and <I>T</I>.
We say that <I>S</I> is a <em>subset</em><A NAME=28342>&#160;</A> of <I>T</I>,
written  <IMG WIDTH=42 HEIGHT=26 ALIGN=MIDDLE ALT="tex2html_wrap_inline63372" SRC="img1082.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1082.gif"  >,
if every element of <I>S</I> is also an element of <I>T</I>.
If there is at least one element of <I>T</I> that is not also an element of <I>S</I>,
we say that <I>S</I> is a
<em>proper subset</em><A NAME=28344>&#160;</A><A NAME=28345>&#160;</A> of <I>T</I>,
written  <IMG WIDTH=42 HEIGHT=23 ALIGN=MIDDLE ALT="tex2html_wrap_inline67364" SRC="img1614.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1614.gif"  >.
We can also reverse the order in which the expressions are written
to get  <IMG WIDTH=43 HEIGHT=23 ALIGN=MIDDLE ALT="tex2html_wrap_inline67366" SRC="img1615.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1615.gif"  > or  <IMG WIDTH=43 HEIGHT=26 ALIGN=MIDDLE ALT="tex2html_wrap_inline67368" SRC="img1616.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1616.gif"  >,
which indicates that <I>T</I> is a
(proper) <em>superset</em><A NAME=28347>&#160;</A><A NAME=28348>&#160;</A><A NAME=28349>&#160;</A>
of <I>S</I>.
<P>
The set comparison operators follow the rule that if  <IMG WIDTH=42 HEIGHT=26 ALIGN=MIDDLE ALT="tex2html_wrap_inline63372" SRC="img1082.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1082.gif"  >
and  <IMG WIDTH=43 HEIGHT=26 ALIGN=MIDDLE ALT="tex2html_wrap_inline63374" SRC="img1083.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1083.gif"  > then  <IMG WIDTH=42 HEIGHT=12 ALIGN=BOTTOM ALT="tex2html_wrap_inline67378" SRC="img1617.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1617.gif"  >,
which is analogous to a similar property of numbers:
 <IMG WIDTH=170 HEIGHT=22 ALIGN=MIDDLE ALT="tex2html_wrap_inline67380" SRC="img1618.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1618.gif"  >.
However, set comparison is unlike numeric comparison in that there
exist sets <I>S</I> and <I>T</I> for which neither  <IMG WIDTH=42 HEIGHT=26 ALIGN=MIDDLE ALT="tex2html_wrap_inline63372" SRC="img1082.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1082.gif"  > nor  <IMG WIDTH=43 HEIGHT=26 ALIGN=MIDDLE ALT="tex2html_wrap_inline63374" SRC="img1083.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1083.gif"  >!
E.g., clearly this is the case for  <IMG WIDTH=69 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline67390" SRC="img1619.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1619.gif"  > and  <IMG WIDTH=70 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline67392" SRC="img1620.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1620.gif"  >.
Mathematically, the relation  <IMG WIDTH=10 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline67394" SRC="img1621.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1621.gif"  > is called
a <em>partial order</em><A NAME=28351>&#160;</A>
because there exist some pairs of sets for which neither  <IMG WIDTH=42 HEIGHT=26 ALIGN=MIDDLE ALT="tex2html_wrap_inline63372" SRC="img1082.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1082.gif"  >
nor  <IMG WIDTH=43 HEIGHT=26 ALIGN=MIDDLE ALT="tex2html_wrap_inline63374" SRC="img1083.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1083.gif"  > holds;
whereas the relation  <IMG WIDTH=10 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline59841" SRC="img397.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img397.gif"  > (among integers, say) is a total order.
<P>
Program&nbsp;<A HREF="page393.html#progbitset3c" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page393.html#progbitset3c"><IMG  ALIGN=BOTTOM ALT="gif" SRC="cross_ref_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/cross_ref_motif.gif"></A> overloads the operators <tt>==</tt> and <tt>&lt;=</tt>
for <tt>SetAsArray</tt> operands.
The former tests its operands for equality
and the latter determines whether the relation  <IMG WIDTH=10 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline67394" SRC="img1621.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1621.gif"  > holds
between its operands.
Both operators return a Boolean result.
The worst-case running time of each of these operations is clearly <I>O</I>(<I>N</I>).
<P>
<P><A NAME="28745">&#160;</A><A NAME="progbitset3c">&#160;</A> <IMG WIDTH=575 HEIGHT=372 ALIGN=BOTTOM ALT="program28356" SRC="img1622.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1622.gif"  ><BR>
<STRONG>Program:</STRONG> <tt>SetAsArray</tt> Class Comparison Operator Definitions<BR>
<P>
<P>
A complete repertoire of comparison operators would also include
definitions for <tt>&lt;</tt>, <tt>&gt;</tt>, <tt>&gt;=</tt> and <tt>!=</tt>.
These operations follow directly from the implementation
shown in Program&nbsp;<A HREF="page393.html#progbitset3c" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page393.html#progbitset3c"><IMG  ALIGN=BOTTOM ALT="gif" SRC="cross_ref_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/cross_ref_motif.gif"></A> (Exercise&nbsp;<A HREF="page414.html#exercisesetscomparison" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page414.html#exercisesetscomparison"><IMG  ALIGN=BOTTOM ALT="gif" SRC="cross_ref_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/cross_ref_motif.gif"></A>).
<P>
<HR><A NAME="tex2html6785" HREF="page394.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page394.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="next_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/next_motif.gif"></A> <A NAME="tex2html6783" HREF="page390.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page390.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="up_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/up_motif.gif"></A> <A NAME="tex2html6779" HREF="page392.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page392.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="previous_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/previous_motif.gif"></A> <A NAME="tex2html6787" HREF="page9.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page9.html"><IMG WIDTH=65 HEIGHT=24 ALIGN=BOTTOM ALT="contents" SRC="contents_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/contents_motif.gif"></A> <A NAME="tex2html6788" HREF="page620.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page620.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="index_motif.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/index_motif.gif"></A> <P><ADDRESS>
<img src="bruno.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/icons/bruno.gif" alt="Bruno" align=right>
<a href="javascript:if(confirm('http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/copyright.html  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/copyright.html'" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/copyright.html">Copyright &#169; 1997</a> by <a href="javascript:if(confirm('http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/signature.html  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/signature.html'" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/signature.html">Bruno R. Preiss, P.Eng.</a>  All rights reserved.

</ADDRESS>
</BODY>
</HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -