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

📄 搜索算法.htm

📁 讲解了搜索算法
💻 HTM
📖 第 1 页 / 共 2 页
字号:
              <TR>
                <TD bgColor=#cccccc height=1><IMG height=1 width=150></TD></TR>
              <TR>
                <TD height=20>
                  <P><A href="http://www.muduhs.com/~yanxm/pds13.htm">- 
                  分支限界</A></P></TD></TR>
              <TR>
                <TD bgColor=#cccccc height=1><IMG height=1 
              width=150></TD></TR></TBODY></TABLE></TD>
          <TD width=40></TD>
          <TD width=603>
            <TABLE cellSpacing=0 cellPadding=0 width="100%">
              <TBODY>
              <TR>
                <TD width="100%" colSpan=2>
                  <P align=right>&nbsp;</P></TD></TR>
              <TR>
                <TD width=250>
                  <P><IMG height=20 src="搜索算法.files/s2.gif" width=20 
                  align=absMiddle border=0> <B>搜索算法</B></P></TD>
                <TD width=340>
                  <P align=right><A 
                  href="http://www.muduhs.com/~yanxm/index1.htm">Index</A>&nbsp;&gt; 
                  <A href="http://www.muduhs.com/~yanxm/pds.htm">Alogri+Data 
                  str</A> &gt; <A 
                  href="http://www.muduhs.com/~yanxm/pds00.htm">常用算法</A> &gt; 
                  搜索</P></TD></TR>
              <TR>
                <TD width="100%" background=搜索算法.files/bg.gif colSpan=2 
                height=1></TD></TR>
              <TR>
                <TD width="100%" colSpan=2>
                  <P><BR>搜索&nbsp;<BR><BR>  搜索算法是利用计算机的高性能来有目的的穷举一个问题的部分或所有的可能情况,从而求出问题的解的一种方法。搜索过程实际上是根据初始条件和扩展规则构造一棵解答树并寻找符合目标状态的节点的过程。<BR>  所有的搜索算法从其最终的算法实现上来看,都可以划分成两个部分──控制结构和产生系统,而所有的算法的优化和改进主要都是通过修改其控制结构来完成的。现在主要对其控制结构进行讨论,因此对其产生系统作如下约定:Function 
                  ExpendNode(Situation:Tsituation;ExpendWayNo:Integer):TSituation;表示对给出的节点状态Sitution采用第ExpendWayNo种扩展规则进行扩展,并且返回扩展后的状态。(本文所采用的算法描述语言为类Pascal。)<BR>一、回溯算法<BR>&nbsp;回溯算法是所有搜索算法中最为基本的一种算法,其采用了一种“走不通就掉头”思想作为其控制结构,其相当于采用了先根遍历的方法来构造解答树,可用于找解或所有解以及最优解。<BR>具体的算法描述如下:<BR>[非递归算法]<BR>&lt;Type&gt;<BR>Node(节点类型)=Record 
                  Situtation:TSituation(当前节点状态);&nbsp;<BR>Way-NO:Integer(已使用过的扩展规则的数目);&nbsp;<BR>End<BR>&lt;Var&gt; 
                  List(回溯表):Array[1..Max(最大深度)] of 
                  Node;<BR>&nbsp;pos(当前扩展节点编号):Integer;<BR>&lt;Init&gt; 
                  List&lt;-0;<BR>&nbsp;pos&lt;-1;<BR>&nbsp;List[1].Situation&lt;-初始状态;<BR>&lt;Main 
                  Program&gt;<BR>While (pos&gt;0(有路可走)) and ([未达到目标]) 
                  do<BR>Begin If pos&gt;=Max then 
                  (数据溢出,跳出主程序);&nbsp;<BR>List[pos].Way-NO:=List[pos].Way-No+1;&nbsp;<BR>If 
                  (List[pos].Way-NO&lt;=TotalExpendMethod) then 
                  (如果还有没用过的扩展规则)<BR>&nbsp;Begin If (可以使用当前扩展规则) 
                  then&nbsp;<BR>Begin (用第way条规则扩展当前节点)<BR>&nbsp; 
                  List[pos+1].Situation:=ExpendNode(List[pos].Situation, 
                  List[pos].Way-NO);<BR>&nbsp;List[pos+1].Way-NO:=0;&nbsp;<BR>pos:=pos+1;&nbsp;<BR>End-If;&nbsp;<BR>End-If&nbsp;<BR>Else&nbsp;<BR>Begin<BR>&nbsp;pos:=pos-1;<BR>&nbsp;End-Else<BR>End-While;</P>
                  <P><BR>[递归算法]<BR>Procedure 
                  BackTrack(Situation:TSituation;deepth:Integer);<BR>Var I 
                  :Integer;<BR>Begin If deepth&gt;Max then 
                  (空间达到极限,跳出本过程);&nbsp;<BR>If Situation=Target then 
                  (找到目标);<BR>&nbsp;For I:=1 to TotalExpendMethod 
                  do<BR>&nbsp;Begin 
                  BackTrack(ExpendNode(Situation,I),deepth+1);&nbsp;<BR>End-For;<BR>End;  <BR>范例:一个M*M的棋盘上某一点上有一个马,要求寻找一条从这一点出发不重复的跳完棋盘上所有的点的路线。  评价:回溯算法对空间的消耗较少,当其与分枝定界法一起使用时,对于所求解在解答树中层次较深的问题有较好的效果。但应避免在后继节点可能与前继节点相同的问题中使用,以免产生循环。二、深度搜索与广度搜索 
                  深度搜索与广度搜索的控制结构和产生系统很相似,唯一的区别在于对扩展节点选取上。由于其保留了所有的前继节点,所以在产生后继节点时可以去掉一部分重复的节点,从而提高了搜索效率。这两种算法每次都扩展一个节点的所有子节点,而不同的是,深度搜索下一次扩展的是本次扩展出来的子节点中的一个,而广度搜索扩展的则是本次扩展的节点的兄弟节点。<BR>在具体实现上为了提高效率,所以采用了不同的数据结构.<BR>[广度搜索]<BR>&lt;Type&gt;&nbsp;<BR>Node(节点类型)=Record 
                  Situtation:TSituation(当前节点状态);&nbsp;<BR>Level:Integer(当前节点深度);<BR>&nbsp;Last 
                  :Integer(父节点);&nbsp;<BR>End<BR>&lt;Var&gt;&nbsp;<BR>List(节点表):Array[1..Max(最多节点数)] 
                  of Node(节点类型);<BR>&nbsp;open(总节点数):Integer;<BR>  
                  close(待扩展节点编号):Integer;<BR>&nbsp; 
                  New-S:TSituation;(新节点)<BR>&lt;Init&gt; 
                  List&lt;-0;<BR>&nbsp;open&lt;-1;<BR>&nbsp;close&lt;-0;<BR>&nbsp;List[1].Situation&lt;- 
                  初始状态;<BR>&nbsp;List[1].Level:=1;<BR>&nbsp;List[1].Last:=0;<BR>&lt;Main 
                  Program&gt;&nbsp;<BR>While (close&lt;open(还有未扩展节点)) and 
                  (open&lt;Max(空间未用完)) and (未找到目标节点) do<BR>&nbsp;Begin<BR>   
                  close:=close+1;<BR>&nbsp;For I:=1 to TotalExpendMethod 
                  do(扩展一层子节点)<BR>&nbsp;Begin 
                  New-S:=ExpendNode(List[close].Situation,I);<BR>&nbsp;If Not 
                  (New-S in List) then (扩展出的节点从未出现过) 
                  Begin<BR>&nbsp;open:=open+1;<BR>&nbsp;List[open].Situation:=New-S;<BR>&nbsp;List[open].Level:=List[close].Level+1;<BR>&nbsp;List[open].Last:=close;<BR>&nbsp;End-If<BR>&nbsp;End-For;<BR>&nbsp;End-While;</P>
                  <P><BR>[深度搜索]</P>
                  <P>&lt;Var&gt;&nbsp;<BR>Open:Array[1..Max] of 
                  Node;(待扩展节点表)<BR>&nbsp;Close:Array[1..Max] of 
                  Node;(已扩展节点表)<BR>&nbsp; openL,closeL:Integer;(表的长度)<BR>&nbsp; 
                  New-S:Tsituation;(新状态)<BR>&lt;Init&gt;<BR>&nbsp;Open&lt;-0;<BR>&nbsp;Close&lt;-0;<BR>&nbsp;OpenL&lt;-1;<BR>CloseL&lt;-0;<BR>&nbsp;Open[1].Situation&lt;- 
                  初始状态;<BR>&nbsp;Open[1].Level&lt;-1;<BR>&nbsp;Open[1].Last&lt;-0;<BR>&lt;Main 
                  Program&gt;<BR>&nbsp;While (openL&gt;0) and (closeL&lt;Max) 
                  and (openL&lt;Max) 
                  do<BR>&nbsp;Begin<BR>&nbsp;closeL:=closeL+1;<BR>&nbsp;Close[closeL]:=Open[openL];<BR>&nbsp;openL:=openL-1;<BR>&nbsp;For 
                  I:=1 to TotalExpendMethod 
                  do(扩展一层子节点)<BR>&nbsp;Begin<BR>&nbsp;New-S:=ExpendNode(Close[closeL].Situation,I);<BR>&nbsp;If 
                  Not (New-S in List) then 
                  (扩展出的节点从未出现过)<BR>&nbsp;Begin<BR>&nbsp;openL:=openL+1;<BR>&nbsp;Open[openL].Situation:=New-S;<BR>&nbsp;Open[openL].Level:=Close[closeL].Level+1;<BR>&nbsp;Open[openL].Last:=closeL;<BR>&nbsp;End-If<BR>&nbsp;End-For;<BR>&nbsp;End;<BR>范例:迷宫问题,求解最短路径和可通路径。评价:广度搜索是求解最优解的一种较好的方法,在后面将会对其进行进一步的优化。而深度搜索多用于只要求解,并且解答树中的重复节点较多并且重复较难判断时使用,但往往可以用分支定界或回溯算法代替&nbsp;<BR></P></TD></TR></TBODY></TABLE></TD>
          <TD width=147>&nbsp;</TD></TR></TBODY></TABLE></TD></TR>
  <TR>
    <TD vAlign=bottom height=81>  
      <TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
        <TBODY>
        <TR bgColor=#cccccc>
          <TD width=800 height=1><IMG height=1 width=800></TD>
          <TD width=459 height=1></TD></TR>
        <TR vAlign=top>
          <TD width=800>
            <TABLE cellSpacing=0 cellPadding=0 width=800>
              <TBODY>
              <TR>
                <TD width=210 height=10></TD>
                <TD width=590 colSpan=2 height=10></TD></TR>
              <TR>
                <TD width=210 height=14>
                  <P align=center><A onfocus=this.blur() 
                  href="http://www.muduhs.com/" target=_blank><FONT face=Verdana 
                  color=#999999 size=1>GO Muduhs WebSite!</FONT></A> </P></TD>
                <TD width=536 height=14>
                  <P><FONT face=Verdana size=1>Copyright &#9426; MuDu - Internet 
                  HighSchool. Some right reserved.</FONT></P></TD>
                <TD width=54 height=14>
                  <P align=right><A onfocus=this.blur() 
                  href="http://www.muduhs.com/~yanxm/pds06.htm#"><FONT 
                  face=Verdana size=1><B>-TOP</B></FONT></A> </P></TD></TR>
              <TR>
                <TD width=210 height=10></TD>
                <TD width=590 colSpan=2 height=10></TD></TR></TBODY></TABLE></TD>
          <TD width=459></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><MAP 
name=ImageMap1><AREA shape=RECT coords=81,1,161,33 
  href="http://www.muduhs.com/~yanxm/pds.htm"><AREA shape=RECT 
  coords=161,1,240,33 href="http://www.muduhs.com/~yanxm/contest.htm"><AREA 
  shape=RECT coords=240,1,320,34 
  href="http://www.muduhs.com/~yanxm/circle.htm"><AREA shape=RECT 
  coords=319,1,401,35 href="http://www.muduhs.com/~yanxm/gellery.htm"><AREA 
  shape=RECT coords=401,2,479,35 
  href="http://www.muduhs.com/~yanxm/board.htm"><AREA shape=RECT 
  coords=1,1,82,33 
href="http://www.muduhs.com/~yanxm/about.htm"></MAP></BODY></HTML>

⌨️ 快捷键说明

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