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

📄 page441.html

📁 wqeqwvrw rkjqhwrjwq jkhrjqwhrwq jkhrwq
💻 HTML
字号:
<HTML>
<HEAD>
<TITLE>Brute-Force and Greedy 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="tex2html7369" HREF="page442.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page442.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="tex2html7367" HREF="page440.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page440.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="tex2html7361" HREF="page440.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page440.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="tex2html7371" 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="tex2html7372" 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>
<H1><A NAME="SECTION0015100000000000000000">Brute-Force and Greedy Algorithms</A></H1>
<A NAME="secalgsgreedy">&#160;</A>
<P>
In this section we consider two closely related algorithm types--brute-force and greedy.
<em>Brute-force algorithms</em><A NAME=32296>&#160;</A>
are distinguished not by their structure or form,
but by the way in which the problem to be solved is approached.
A brute-force algorithm solves a problem in the most simple,
direct or obvious way.
As a result, such an algorithm can end up doing far more work
to solve a given problem
than a more clever or sophisticated algorithm might do.
On the other hand,
a brute-force algorithm is often easier to implement
than a more sophisticated one and,
because of this simplicity,
sometimes it can be more efficient.
<P>
Often a problem can be viewed as a sequence of decisions to be made.
For example, consider the problem of finding the best way
to place electronic components on a circuit board.
To solve this problem we must decide
where on the board to place each component.
Typically, a brute-force algorithm solves such a problem
by exhaustively enumerating all the possibilities.
I.e., for every decision we consider each possible outcome.
<P>
A greedy algorithm is one that makes the sequence of decisions (in some order)
such that once a given decision has been made,
that decision is never reconsidered.
For example,
if we use a greedy algorithm to place the components on the circuit board,
once a component has been assigned a position it is never again moved.
Greedy algorithms can run significantly faster than brute force ones.
Unfortunately, it is not always the case that a greedy strategy
leads to the correct solution.
<P>
<BR> <HR>
<UL> 
<LI> <A NAME="tex2html7373" HREF="page442.html#SECTION0015110000000000000000" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page442.html#SECTION0015110000000000000000">Example-Counting Change</A>
<LI> <A NAME="tex2html7374" HREF="page445.html#SECTION0015120000000000000000" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page445.html#SECTION0015120000000000000000">Example-0/1 Knapsack Problem</A>
</UL>
<HR><A NAME="tex2html7369" HREF="page442.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page442.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="tex2html7367" HREF="page440.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page440.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="tex2html7361" HREF="page440.html" tppabs="http://dictator.uwaterloo.ca/Bruno.Preiss/books/opus4/html/page440.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="tex2html7371" 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="tex2html7372" 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 + -