Java中朴素后缀树的实现

Java中朴素后缀树的实现,java,algorithm,suffix-tree,Java,Algorithm,Suffix Tree,我正在尝试用一个简单的构建算法来编写后缀树类,这个算法是O(m^2),而不是Ukkonen 我的疑问在于如何表现这棵树。到目前为止,我已经得到了这个。但我不认为这是节点和边的写类结构。关于如何维护节点和边之间的映射/关系的任何建议。重要的一点是,在edge中,我们只存储开始和结束索引以节省空间 class suffixTree{ Node[] nodes; Edge[] edge; } class Node{ int node_id; Edge[] outgoingEdges; }

我正在尝试用一个简单的构建算法来编写后缀树类,这个算法是O(m^2),而不是Ukkonen

我的疑问在于如何表现这棵树。到目前为止,我已经得到了这个。但我不认为这是节点和边的写类结构。关于如何维护节点和边之间的映射/关系的任何建议。重要的一点是,在edge中,我们只存储开始和结束索引以节省空间

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;
}
类后缀树{
//树只需要知道根节点。
节根;
}
//节点包含从第一个字符到第二个字符的映射
//与之相对应的边。
//它不需要知道其他任何事情。
类节点{
地图边缘地图;
}
//边仅包含子字符串的开始索引和结束索引
//和目标节点。
阶级边缘{
国际标准指数;
内部索引;
节点目的地;
}
最重要的变化是:

  • 清除所有三个类中的冗余信息

  • 使用引用而不是数组和索引


  • 我不明白为什么需要
    节点
    。您应该只需要对根节点的引用。每个叶节点都应该在字符串中包含对其偏移量的引用<代码>边缘。不需要开始节点id。非常感谢您的回复。你能详细说明一下吗。我告诉过你我会对班级结构做些改变。剩下的没问题。非常感谢@Kraskevich。没有拿到地图边缘图。您认为边对应的字符是什么?@Andy897此边对应的子字符串的第一个字符。