您可以帮助我了解以下图形搜索问题吗?

时间:2019-09-10 13:28:00

标签: dictionary graph-theory depth-first-search

我正在努力解决问题;我目前处于流程的understanding阶段;因此,我的问题。

这是我需要了解的graph search问题:

问题:给定一个句子,该句子由一系列单词组成,所有单词都含糊不清,定义了一种最佳方法,给了字典,将其分解成单词。

请不要为我解决这个问题;请给我一个例子,即一个输入和相应的输出;例如,如果问题是对数字求平方,则该示例将如下所示:

given: 4; expected: 16

由于这是一个图搜索问题,因此我打算通过深度优先搜索解决该问题;这是Scheme中的实现:

(define (depth node graph visited)
    (cond ((null? node) (reverse visited))
          ((member (car node) visited)
           (depth (cdr node) graph visited))
          (else (depth (append (nexts (car node) graph) (cdr node))
                       graph
                       (cons (car node) visited)))))
(define nexts
    (lambda (node graph)
      (cond ((null? graph) '())
            ((eq? node (car (car graph)))
             (cons (car (cdr (car graph))) (nexts node (cdr graph))))
            (else (nexts node (cdr graph))))))

谢谢!祝你今天愉快。 -职位

0 个答案:

没有答案