gpt4 book ai didi

具有相同代码的算法在应用于不同容器时可以实现不同的有用目标

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:24:00 25 4
gpt4 key购买 nike

<分区>

广度优先搜索和深度优先搜索是两种相同的算法,除了它们的作用和使用的数据结构不同。

广度优先搜索:

q := queue
q.append(root node of tree)
while q is not empty:
n := q.pop()
if n is the node being searched for:
return n
if n has children:
c := children of node
for i in c:
q.push(i)

深度优先搜索:

s := stack
s.append(root node of tree)
while s is not empty:
n := s.pop()
if n is the node being searched for:
return n
if n has children:
c := children of node
for i in c:
s.push(i)

是否有任何其他算法(或数据结构)可以像这样工作?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com