I am currently studying Dan Gusfield book (Algorithms on Strings, Trees and Sequences) and I am trying to solve the below exercise:
Suppose we are given a tree where each edge is labeled with one or more characters, and we are given a pattern P. The label of a subpath in the tree is the concatenation of the labels on the edges in the subpath. The problem is to find all subpaths of paths starting at the root that are labeled with pattern P. Note that although the subpath must be part of a path directed from the root, the subpath itself need not start at the root (see Figure 2.3). Give an algorithm for this problem that runs in time proportional to the total number of characters on the edges of the tree plus the length of P.
To be honest i am completely stuck and I can't think of an algorithm that can solve this. I guess we will use dynamic programming?
Aucun commentaire:
Enregistrer un commentaire