[英]naive suffix tree implementation in Java
我正在嘗試用一個天真的構建算法編寫后綴樹類,該算法是O(m ^ 2)而不是Ukkonen。
我懷疑如何代表樹。 到目前為止,我有這個。 但我不認為這是節點和邊的寫類結構。 關於如何維護節點和邊緣之間的映射/關系的任何建議。 重要的一點是,在邊緣我們只存儲起始和結束索引以節省空間。
class suffixTree{
Node[] nodes;
Edge[] edge;
}
class Node{
int node_id;
Edge[] outgoingEdges;
}
class Edge{
int start_index;
int end_index;
int start_node_id;
int end_node_id;
}
我會這樣做:
class SuffixTree {
// A tree only needs to know about the root Node.
Node root;
}
// A Node contains a mapping from the first character to
// an Edge that corresponds to it.
// It doesn't need to know about anything else.
class Node {
Map<Character, Edge> edgeMap;
}
// An Edge contains only the start and the end index of the substring
// and the destination Node.
class Edge {
int startIndex;
int endIndex;
Node destination;
}
最重要的變化是:
擺脫所有三個類中的冗余信息。
使用引用而不是數組和索引。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.