这是一个双重问题,因为我对如何最有效地实现这一点缺乏想法.
我有一个150,000字的字典,存储在Trie实现中,这是我的特定实现:
向用户提供两个单词.目标是从起始单词到结束单词找到其他英语单词的最短路径(由一个字符改变).
例如:
开始:狗
结束:猫
路径:狗,点,婴儿床,猫
路径:狗,Cog,日志,沼泽,机器人,婴儿床,猫
路径:狗,美国能源部,乔,喜悦,Jot,婴儿床,猫
我当前的实现经历了几次迭代,但最简单的我可以提供伪代码(因为实际代码是几个文件):
var start = "dog";
var end = "cat";
var alphabet = [a, b, c, d, e .... y, z];
var possible_words = [];
for (var letter_of_word = 0; letter_of_word < start.length; letter_of_word++) {
for (var letter_of_alphabet = 0; letter_of_alphabet < alphabet.length; letter_of_alphabet++) {
var new_word = start;
new_word.characterAt(letter_of_word) = alphabet[letter_of_alphabet];
if (in_dictionary(new_word)) {
add_to.possible_words;
}
}
}
function bfs() {
var q = [];
... usual bfs implementation here .. …Run Code Online (Sandbox Code Playgroud) 我似乎无法将从我的codeigniter应用程序传递的会话数据返回到我的includes文件夹中的脚本.从我在其他答案中读到的内容,我需要设置我session_id()能够重新加入会话session_start().
ROOT /
.. /application
.. /system
.. /includes
.. /Events.php <- I need access from here
Run Code Online (Sandbox Code Playgroud)
理论上,下面的代码应该起作用,至少根据其他答案,因为新的CI会话库传递给本地会话.
session_id($_COOKIE['ci_session']);
session_start();
var_dump($_SESSION); // returns null
Run Code Online (Sandbox Code Playgroud)
我是误会吗?
我真的被困在学校的任务上.我们正在学习通用类型,也许这不仅是我完全理解它们,而是作为我们必须实现的第一个方法之一的一部分:
我们有:
public static <T> T min(Collection<T> c, Comparator<T> comp) {
return null
}
Run Code Online (Sandbox Code Playgroud)
和要求:
从Collection c供应的定义中选择最小值Comparator comp.IllegalArgumentException
如果c或comp为null,则此方法抛出if,如果c为空,则抛出NoSuchElementExceptionif.此方法不会更改Collection c.
所以我到了这里:
public static <T> T min(Collection<T> c, Comparator<T> comp)
throws IllegalArgumentException, NoSuchElementException {
if (c != null && comp != null) {
if (!c.isEmpty()) {
} else {
throw new NoSuchElementException();
}
} else {
throw new IllegalArgumentException();
}
}
Run Code Online (Sandbox Code Playgroud)
我们必须使用比较器排序,但不能使用Collections类.我真的需要一些指导才能开始,我不是要求你为我做任务!
algorithm ×1
codeigniter ×1
collections ×1
comparator ×1
java ×1
javascript ×1
performance ×1
php ×1
python ×1
session ×1
sorting ×1