📄 page459.html
字号:
<HTML>
<HEAD>
<TITLE>Running Time of Divide-and-Conquer Algorithms</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="tex2html7592" HREF="page460.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page460.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="tex2html7590" HREF="page455.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page455.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="tex2html7584" HREF="page458.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page458.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="tex2html7594" 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="tex2html7595" 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>
<H2><A NAME="SECTION0015340000000000000000">Running Time of Divide-and-Conquer Algorithms</A></H2>
<P>
A number of divide-and-conquer algorithms are presented
in the preceding sections.
Because these algorithms have a similar form,
the recurrences which give the running times of the algorithms
are also similar in form.
Table <A HREF="page459.html#tblalgstimes" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page459.html#tblalgstimes"><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> summarizes the running times
of Programs <A HREF="page456.html#progalgs1c" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page456.html#progalgs1c"><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>, <A HREF="page457.html#progalgs2c" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page457.html#progalgs2c"><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> and <A HREF="page458.html#progalgs3c" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page458.html#progalgs3c"><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>
<P><A NAME="32997"> </A>
<P>
<A NAME="tblalgstimes"> </A>
<DIV ALIGN=CENTER><P ALIGN=CENTER><TABLE COLS=3 BORDER FRAME=HSIDES RULES=GROUPS>
<COL ALIGN=LEFT><COL ALIGN=LEFT><COL ALIGN=LEFT>
<TBODY>
<TR><TD VALIGN=BASELINE ALIGN=LEFT NOWRAP>
program </TD><TD VALIGN=BASELINE ALIGN=LEFT NOWRAP> recurrence </TD><TD VALIGN=BASELINE ALIGN=LEFT NOWRAP> solution </TD></TR>
</TBODY><TBODY>
<TR><TD VALIGN=BASELINE ALIGN=LEFT NOWRAP>Program <A HREF="page456.html#progalgs1c" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page456.html#progalgs1c"><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> </TD><TD VALIGN=BASELINE ALIGN=LEFT NOWRAP> <I>T</I>(<I>n</I>)=<I>T</I>(<I>n</I>/2)+<I>O</I>(1) </TD><TD VALIGN=BASELINE ALIGN=LEFT NOWRAP> <IMG WIDTH=56 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline59891" SRC="img403.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img403.gif" > </TD></TR>
<TR><TD VALIGN=BASELINE ALIGN=LEFT NOWRAP>
Program <A HREF="page457.html#progalgs2c" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page457.html#progalgs2c"><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> </TD><TD VALIGN=BASELINE ALIGN=LEFT NOWRAP> <I>T</I>(<I>n</I>)=2<I>T</I>(<I>n</I>/2)+<I>O</I>(1) </TD><TD VALIGN=BASELINE ALIGN=LEFT NOWRAP> <I>O</I>(<I>n</I>) </TD></TR>
<TR><TD VALIGN=BASELINE ALIGN=LEFT NOWRAP>
Program <A HREF="page458.html#progalgs3c" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page458.html#progalgs3c"><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> </TD><TD VALIGN=BASELINE ALIGN=LEFT NOWRAP> <I>T</I>(<I>n</I>)=2<I>T</I>(<I>n</I>/2)+<I>O</I>(<I>n</I>) </TD><TD VALIGN=BASELINE ALIGN=LEFT NOWRAP> <IMG WIDTH=68 HEIGHT=24 ALIGN=MIDDLE ALT="tex2html_wrap_inline59897" SRC="img405.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img405.gif" > </TD></TR>
</TBODY>
<CAPTION ALIGN=BOTTOM><STRONG>Table:</STRONG> Running Times of Divide-and-Conquer Algorithms</CAPTION></TABLE>
</P></DIV><P>
<P>
In this section we develop a general recurrence
that characterizes the running times of many divide-and-conquer algorithms.
Consider the form of a divide-and-conquer algorithm to solve a given problem.
Let <I>n</I> be a measure of the size of the problem.
Since the divide-and-conquer paradigm is essentially recursive,
there must be a base case.
I.e., there must be some value of <I>n</I>, say <IMG WIDTH=16 HEIGHT=15 ALIGN=MIDDLE ALT="tex2html_wrap_inline59043" SRC="img238.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img238.gif" >,
for which the solution to the problem is computed directly.
We assume that the worst-case running time for the base case
is bounded by a constant.
<P>
To solve an arbitrarily large problem using divide-and-conquer,
the problem is <em>divided</em> into a number smaller problems,
each of which is solved independently.
Let <I>a</I> be the number of smaller problems to be solved
( <IMG WIDTH=39 HEIGHT=23 ALIGN=MIDDLE ALT="tex2html_wrap_inline68785" SRC="img1888.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1888.gif" >, <IMG WIDTH=37 HEIGHT=25 ALIGN=MIDDLE ALT="tex2html_wrap_inline68787" SRC="img1889.gif" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/img1889.gif" >).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -