Skip to content

Commit 1fbd9ec

Browse files
committed
[rosalind] add problem description to trie example
1 parent d08200a commit 1fbd9ec

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

categories/rosalind/trie-grondilu.pl

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,46 @@
66
77
=AUTHOR L. Grondin
88
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+
940
L<http://rosalind.info/problems/trie/>
1041
11-
Sample dataset:
42+
=head2 Sample dataset:
1243
1344
ATAGA
1445
ATC
1546
GAT
1647
17-
Sample output:
48+
=head2 Sample output:
1849
1950
1 2 A
2051
2 3 T
@@ -26,7 +57,7 @@
2657
8 9 A
2758
9 10 T
2859
29-
Usage:
60+
=head2 Usage:
3061
3162
$ perl6 trie-grondilu.pl
3263

0 commit comments

Comments
 (0)