由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - [算法] word ladder problem (转载)
相关主题
shortest path algorithm(dijkstra)的变形一道C++面试题
问问Boost library, 尤其是Boost Graph Library (BGL)问一个 关于地图 (GIS) 的 编程问题
An interview questionone question about algorithm
[合集] huge map怎么算最短路径?这个图问题的复杂度是多少呢
请教一个算法题关于shortest path的priority_queue 的问题
Leetcode的系统真是弱爆了 (转载)[合集] 再论auto_ptr/SmartPtr和内存泄漏
Principal Software Engineer,还是Architect?google map 的问题
这次选举把大数据牌子砸了吧。两个矩阵的算法题
相关话题的讨论汇总
话题: ladder话题: word话题: rungs话题: shortest话题: interior
进入Programming版参与讨论
1 (共1页)
i**********e
发帖数: 1145
1
【 以下文字转载自 JobHunting 讨论区 】
发信人: dongfeiwww (feifei), 信区: JobHunting
标 题: [算法] word ladder problem
发信站: BBS 未名空间站 (Mon Jan 24 23:59:22 2011, 美东)
amazon好像出过此题,简单的说,就是一个原始字符串,一个目标串,求最少的变换的
路径,要求每次变化后的词都在一个字典中。
有些人说bfs,还是dijkstra算法?
下面是原题
// http://www.cs.duke.edu/csed/newapt/allwordladder.html
A word ladder is a sequence of words in which each word can be transformed
into the next word by changing one letter. For example, the word ladder
below changes 'lot' to 'log'.
lot dot dog log
This is not the shortest word-ladder between 'lot' and 'log' since the
former can be immediately changed to the latter yielding a word ladder of
length two:
lot log
The first and last words in a word ladder are the anchor rungs of the ladder
. Any other words are interior rungs. For example, there are three interior
rungs in the ladder below between 'smile' and 'evote'.
smile smite smote emote evote
In this problem you'll write a method that has parameters representing
potential interior rungs: an array of strings (these may by nonsense or
English words), and the anchor rungs --- two strings. Your code must
determine the shortest word ladder between the anchor rungs that uses at
least one interior rung, and the number of such ladders. Return an array
containing two ints: the first is the length of the shortest valid word
ladder and the second is the number of shortest ladders. If there are no
valid ladders return [0,0].
i**********e
发帖数: 1145
2
我的解法在这里,感觉好像还可以进行优化,欢迎各位讨论讨论。
http://www.mitbbs.com/article/JobHunting/31777619_0.html
g*********s
发帖数: 1782
3
"变化"怎么定义?一次只能改动一个字母?能增/删吗?
如果是一次只能改一个,那bfs够了。
bfs可看作dijkstra的特例,dijkstra又可看成A*的特例。

transformed

【在 i**********e 的大作中提到】
: 我的解法在这里,感觉好像还可以进行优化,欢迎各位讨论讨论。
: http://www.mitbbs.com/article/JobHunting/31777619_0.html

t****t
发帖数: 6806
4
牛顿法求sqrt用的函数是y=x^2-a=0...不是用的sqrt.
要取f''(x)同号的那一侧, 即根的右侧比较好.
g*********s
发帖数: 1782
5
为什么根右侧好?怎么证明任意初值最后都能收敛呢?

【在 t****t 的大作中提到】
: 牛顿法求sqrt用的函数是y=x^2-a=0...不是用的sqrt.
: 要取f''(x)同号的那一侧, 即根的右侧比较好.

t****t
发帖数: 6806
6
画个图看看就知道了. 注意我没说任意初值都能收敛, 有条件的. 不过对这个问题, 确
实任意初值都能收敛的, 有快有慢就是了.

【在 g*********s 的大作中提到】
: 为什么根右侧好?怎么证明任意初值最后都能收敛呢?
1 (共1页)
进入Programming版参与讨论
相关主题
两个矩阵的算法题请教一个算法题关于shortest path的
ask help for several interview questions (转载)Leetcode的系统真是弱爆了 (转载)
算法问题。Principal Software Engineer,还是Architect?
matlab里边的 null matrix怎么个用法。这次选举把大数据牌子砸了吧。
shortest path algorithm(dijkstra)的变形一道C++面试题
问问Boost library, 尤其是Boost Graph Library (BGL)问一个 关于地图 (GIS) 的 编程问题
An interview questionone question about algorithm
[合集] huge map怎么算最短路径?这个图问题的复杂度是多少呢
相关话题的讨论汇总
话题: ladder话题: word话题: rungs话题: shortest话题: interior