|
6 | 6 |
|
7 | 7 | =AUTHOR L. Grondin
|
8 | 8 |
|
| 9 | +=head2 Problem |
| 10 | +
|
| 11 | +Given a collection of strings, their trie (often pronounced "try" to avoid |
| 12 | +ambiguity with the general term tree) is a rooted tree formed as follows. |
| 13 | +For every unique first symbol in the strings, an edge is formed connecting |
| 14 | +the root to a new vertex. This symbol is then used to label the edge. |
| 15 | +
|
| 16 | +We may then iterate the process by moving down one level as follows. Say |
| 17 | +that an edge connecting the root to a node I<v> is labeled with 'A'; then we |
| 18 | +delete the first symbol from every string in the collection beginning with |
| 19 | +'A' and then treat v as our root. We apply this process to all nodes that |
| 20 | +are adjacent to the root, and then we move down another level and continue. |
| 21 | +See Figure 1 for an example of a trie. |
| 22 | +
|
| 23 | +As a result of this method of construction, the symbols along the edges of |
| 24 | +any path in the trie from the root to a leaf will spell out a unique string |
| 25 | +from the collection, as long as no string is a prefix of another in the |
| 26 | +collection (this would cause the first string to be encoded as a path |
| 27 | +terminating at an internal node). |
| 28 | +
|
| 29 | +Given: A list of at most 100 DNA strings of length at most 100 bp, none of |
| 30 | +which is a prefix of another. |
| 31 | +
|
| 32 | +Return: The adjacency list corresponding to the trie I<T> for these |
| 33 | +patterns, in the following format. If I<T> has I<n> nodes, first label the |
| 34 | +root with 1 and then label the remaining nodes with the integers 2 through |
| 35 | +I<n> in any order you like. Each edge of the adjacency list of I<T> will be |
| 36 | +encoded by a triple containing the integer representing the edge's parent |
| 37 | +node, followed by the integer representing the edge's child node, and |
| 38 | +finally the symbol labeling the edge. |
| 39 | +
|
9 | 40 | L<http://rosalind.info/problems/trie/>
|
10 | 41 |
|
11 |
| -Sample dataset: |
| 42 | +=head2 Sample dataset: |
12 | 43 |
|
13 | 44 | ATAGA
|
14 | 45 | ATC
|
15 | 46 | GAT
|
16 | 47 |
|
17 |
| -Sample output: |
| 48 | +=head2 Sample output: |
18 | 49 |
|
19 | 50 | 1 2 A
|
20 | 51 | 2 3 T
|
|
26 | 57 | 8 9 A
|
27 | 58 | 9 10 T
|
28 | 59 |
|
29 |
| -Usage: |
| 60 | +=head2 Usage: |
30 | 61 |
|
31 | 62 | $ perl6 trie-grondilu.pl
|
32 | 63 |
|
|
0 commit comments