page434.html

来自「Data Structures And Algorithms With Obje」· HTML 代码 · 共 59 行

HTML
59
字号
<HTML><HEAD><TITLE>Brute-Force and Greedy Algorithms</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="tex2html6172" HREF="page435.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html6170" HREF="page433.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html6164" HREF="page433.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html6174" HREF="page611.html"><IMG WIDTH=43 HEIGHT=24 ALIGN=BOTTOM ALT="index" SRC="../icons/index_motif.gif"></A> <BR><HR><H1><A NAME="SECTION0014100000000000000000">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=32120>&#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 workto solve a given problemthan a more clever or sophisticated algorithm might do.On the other hand,a brute-force algorithm is often easier to implementthan 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 wayto place electronic components on a circuit board.To solve this problem we must decidewhere on the board to place each component.Typically, a brute-force algorithm solves such a problemby exhaustively enumerating all the possibilities.That is, 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 strategyleads to the correct solution.<P><BR> <HR><UL> <LI> <A NAME="tex2html6175" HREF="page435.html#SECTION0014110000000000000000">Example-Counting Change</A><LI> <A NAME="tex2html6176" HREF="page438.html#SECTION0014120000000000000000">Example-0/1 Knapsack Problem</A></UL><HR><A NAME="tex2html6172" HREF="page435.html"><IMG WIDTH=37 HEIGHT=24 ALIGN=BOTTOM ALT="next" SRC="../icons/next_motif.gif"></A> <A NAME="tex2html6170" HREF="page433.html"><IMG WIDTH=26 HEIGHT=24 ALIGN=BOTTOM ALT="up" SRC="../icons/up_motif.gif"></A> <A NAME="tex2html6164" HREF="page433.html"><IMG WIDTH=63 HEIGHT=24 ALIGN=BOTTOM ALT="previous" SRC="../icons/previous_motif.gif"></A>  <A NAME="tex2html6174" 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 + =
减小字号Ctrl + -
显示快捷键?