The Way 2 Inner Peace.

伸展树

深度优先搜索和广度优先搜索(非递归).

Qians posted @ 2012年10月30日 16:22 in python with tags python udacity 算法 , 3220 阅读

来自udacity cs215 unit3-12

深度优先:

  1. 将openlist中的最后一项取出.
  2. 将其未标记的邻项标记为已访问.并放入openlist.

  3. 重复此步骤1.2.直到openlist为空.

例:

 

上图中图从P开始,openlist:

[p]

[r,s,q]

[r,s,t]

[r,s,u]

[r,s]

[r]

[]

广度优先则是将openlist中的第一项取出.有:

[p]

[r,s,q]

[s,q,u]

[q,u]

[u,t]

[t]

[]

Grabbing the last element means you are using a "stack". Grabbing the first means you are using a "queue". -MLL

深度优先使用的是栈.广度优先使用的是队列.

参考代码

seo service UK 说:
2024年1月16日 15:25

I like your post and also like your website because your website is very fast and everything in this website is good. Keep writing such informative posts. I have bookmark your website. Thanks for sharin


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter