TRIE
TRIE
echizen_tm
July 23, 2011
(1 slides)
1 TRIE (3 slides)
2 TRIE (25 slides)
3 LOUDS (13 slides)
4 LOUDS (7 slides)
(1 slides)
(2 slides)
(1/1)
ID echizen_tm
EchizenBlog-Zwei
web
Project Euler
1
TRIE
TRIE (1/3)
Edward Fredkin (1960)
(Key-Value Store)
darts(@taku910 ) tx-trie(@hillbig )
marisa-trie(@s5yata )
TRIE (2/3)
TRIE
KVS
O(1)
TRIE
( O(NlogN))
TRIE (3/3)
Patricia Tree ( )
Double Array ( )
base check TRIE
darts
LOUDS
( Level-Order Unary Degree Sequence)
tx-trie marisa-trie
XBW Transform(X Burrows-Wheeler )
BWT
2
TRIE
TRIE (1/25)
TRIE
erika-trie
Compressed Suffix Array tsubomi
TRIE (2/25)
darts
tx-trie
erika-trie
marisa-trie
TRIE (3/25)
C/C++
TRIE (4/25)
TRIE (5/25)
TRIE
TRIE
TRIE
TRIE
TRIE
TRIE
TRIE
TRIE (6/25)
TRIE( LOUDS)
TRIE
search() read() write()
TRIE
class trie {
public:
virtual void search(const string &key,
vector<pair<string, string>> &value) = 0;
virtual bool read(const char *filename) = 0;
virtual void write(const char *filename) = 0;
};
TRIE (7/25)
TRIE
basic_trie
trie
add()
add() TRIE
class basic_trie : public trie {
public:
void add(const string &key, const string &value);
void search(const string &key,
vector<pair<string, string>> &value);
bool read(const char *filename);
void write(const char *filename);
};
TRIE (8/25)
TRIE (9/25)
20
15
10
TRIE (10/25)
( = )
( = )
( )
Patricia
UTF8 1
TRIE (11/25)
string
bool
class node {
public:
string label_;
bool is_value_;
node(const string &, bool);
~node();
};
TRIE (12/25)
element
int elementID
vector
element vector TRIE
element ID
class element {
public:
node
n_;
vector<int> a_;
element(const node &);
~element();
};
TRIE (13/25)
class basic_trie {
vector<element> g_;
};
class element {
node
n_;
vector<int> a_;
};
class node {
string label_;
bool is_value_;
};
TRIE (14/25)
TRIE
TRIE (15/25)
20
20
20
TRIE (16/25)
10
10
20
10
TRIE (17/25)
15
15
20
15
10
TRIE (18/25)
for (j = 0; j < [Link](); j++) {
iterator i = g_[pos].a_.begin(); 1
iterator e = g_[pos].a_.end();
while (i != e) {
if (g_[*i].n_.is_value_ == false &&
g_[*i].n_.label_ == key[j]) { pos = *i; break; }
} i++;
if (i == e) {
g_[pos].a_.push_back(g_.size());
g_.push_back(element(node(key[j])));
}
}
TRIE (19/25)
TRIE
TRIE (20/25)
20
15
10
TRIE (21/25)
DFS( )
20
20
20
15
15
15
10
TRIE (22/25)
for (j = 0; j < [Link](); j++) {
iterator i = g_[pos].a_.begin(); 1
iterator e = g_[pos].a_.end();
while (i != e) {
if (g_[*i].n_.is_value_ == false &&
g_[*i].n_.label_ == key[j]) { pos = *i; break; }
} i++;
if (i == e) { return }
}
retrieve(pos, key, values);
TRIE (23/25)
DFS( )
BFS( )
TRIE DFS
TRIE (24/25)
( )
(C/C++ STL )
TRIE (25/25)
TRIE
LOUDS
3
LOUDS
LOUDS (1/13)
G. Jacobson (1989)
Level-Order Unary Degree Sequence
TRIE LOUDS
O(NlogN) O(N)
ID
ID
LOUDS (2/13)
LOUDS
LOUDS (3/13)
(Level-Order)
0
2
1
3
6 20
5
8
7
9 15
10 10
LOUDS (4/13)
(Degree)
Unary
0 (2)
1 (2)
3 (1)
6 20 (0)
4 (1)
7 (1)
9 15 (0)
2 (1)
5 (1)
8 (1)
10 10 (0)
LOUDS (5/13)
Level-Order (Unary Degree)
(Sequence)
(2)
(2)
(1)
(1)
(1)
(1)
10
20
(0)
(1)
15
(1) (0)
10
(0)
LOUDS
LOUDS (6/13)
1
3
(
1 (2)
3 (1)
4 (1)
LOUDS (7/13)
(1 )
(2)
(2)
(1)
(1)
(1)
(1)
10
20
(0)
(1)
15
(1) (0)
10
(0)
1
3
LOUDS (8/13)
1
2+1=3
(3 )
(2)
(2)
(1)
(1)
(1)
(1)
10
20
(0)
(1)
15
(1) (0)
10
(0)
1
3
LOUDS (9/13)
LOUDS (10/13)
5
8
5 (1)
8 (1)
LOUDS (11/13)
(5 )
2+2+1+1+1=7
(2)
(2)
(1)
(1)
(1)
(1)
10
20
(0)
(1)
15
(1) (0)
10
(0)
5 (1)
8 (1)
LOUDS (12/13)
1
(2 + 2 + 1 + 1 + 1) + 1 = 7 + 1 = 8
(8 )
(2)
(2)
(1)
(1)
(1)
(1)
10
20
(0)
(1)
15
(1) (0)
10
(0)
5 (1)
8 (1)
LOUDS (13/13)
LOUDS LOUDS
4
LOUDS
LOUDS (1/7)
louds_trie
trie
basic_trie louds
build()
class louds_trie : public trie {
public:
void build(const basic_trie &bt);
void search(const string &key,
vector<pair<string, string>> &value);
bool read(const char *filename);
void write(const char *filename);
};
LOUDS (2/7)
LOUDS TRIE
n ( )
Unary
Unary
LOUDS (3/7)
VerticalCode( , 2005)
( )
dag_vector
LOUDS(Level-Order Unary Degree Sequence)
LOVES(Level-Order VErtical code Sequence)
LOUDS (4/7)
VerticalCode
push(d) d
diff(pos) pos
get(pos) pos
typedef unsigned long long ullong;
class vertical_code {
public:
void push(ullong d);
ullong diff(ullong pos);
ullong get(ullong pos);
};
LOUDS (5/7)
(LOUDS) VerticalCode
node vector
class louds_trie : public trie {
vertical_code vc_;
vector<node> nodes_;
};
LOUDS (6/7)
trie
search()
OK
basic_trie
i = g_[pos].a_.begin();
e = g_[pos].a_.end();
while (i != e) { ......; i++; }
louds_trie
i = vc_->get(pos 1) + 1;
e = i + vc->diff(pos);
while (i != e) { ......; i++; }
LOUDS (7/7)
louds_trie
basic_trie
basic_trie (6.1MB) / louds_trie (3.1MB)
(117957 / 3.9MB)
basic_trie (24.9MB) / louds_trie (14.3MB)
( )
basic_trie (7.3sec) / louds_trie (7.5sec)
(1/1)
TRIE
Patricia, Double Array, LOUDS, XBW
TRIE KVS
TRIE
darts, tx-trie, marisa-trie
TRIE
erika-trie
TRIE & LOUDS
(1/2)
darts ([Link]
tx-trie ([Link]
marisa-trie ([Link]
Web
@ ([Link]
Something in C/C++/C# ([Link]
Preferred Research
([Link]
(2/2)
Trie memory (E. Fredkin, 1960)
PATRICIAPractical Algorithm To Retrieve
Information Coded in Alphanumeric
(D. R. Mollison, 1968)
An efficient digital search algorithm by using a doublearray structure (Aoe, J.-I. 1989)
Space-efficient Static Trees and Graphs
(G. Jacobson, 1989)
Structuring labeld trees for optimal succinctness, and
beyond (P. Ferragina, and et. al. , 2005)