Presentation is loading. Please wait.

Presentation is loading. Please wait.

The TRIE Amihood Amir.

Similar presentations


Presentation on theme: "The TRIE Amihood Amir."— Presentation transcript:

1 The TRIE Amihood Amir

2 Labeled Trees Edge Labeled Tree: T=(V,E,ℓ) Where ℓ:VΣ,
Σ is the alphabet. Example: Σ={A,B,C} A A B C B

3 Path String A path v0,…,vi in an edge labeled tree defines the path string ℓ(v0),…,ℓ(vi) of the labels of the vertices on the path. Example: Path: A A B C B Path string: AAB

4 Root Paths A root path v0,…,vi in an edge labeled tree is a path that starts at the root, i.e. v0 is the root of the tree. Example: Root Path: A Not Root Path: A B C B

5 Longest Common Prefix Let S=S[1],…,S[m] and T=T[1],…,T[n] be two strings over alphabet Σ. The Longest Common Prefix (LCP) of S and T is the string a[1],…,a[k] such that a[i]=S[i]=T[i], i=1,…,k and such that S[k+1]≠T[k+1]. Example: The LCP of ABCAABCDABCCC and ABCAABCDACACC is: ABCAABCDA

6 reTRIEval We define a Trie T of n strings S1 = S1[1],…,S1[m1]
Sn = Sn[1],…,Sn[mn] over alphabet Σ by induction on n as follows: Let Λ,$ є Σ.

7 reTRIEval – base case For n=1: S1 = S1[1],…,S1[m1] The trie is: . . .
Λ For n=1: S1 = S1[1],…,S1[m1] The trie is: S1[1] . . . S1[m1] $

8 reTRIEval – inductive case (1)
Assume we have defined he trie Tn of n strings. The trie Tn+1 of the n+1 strings: S1 = S1[1],…,S1[m1] S2 = S2[1],…,S2[m2] Sn = Sn[1],…,Sn[mn] Sn+1 = Sn+1[1],…,Sn+1[mn+1] Is defined as follows:

9 reTRIEval - inductive case (2)
Let Tn be the trie of the n strings S1 = S1[1],…,S1[m1] S2 = S2[1],…,S2[m2] Sn = Sn[1],…,Sn[mn] And let a[1],…a[k] be the longest LCP(Sn+1,Si), i=1,…,n.

10 reTRIEval – inductive case (3)
Concatenate the path: To the node where the root path of string a[1],…,a[k] ends. The resulting tree is Tn+1. Sn+1[k+1] . . . Sn+1[mn+1] $

11 Trie construction Example
ABCABC ABB ABBA ABCB BBAB BABC

12 Trie construction Time
For a Trie T of n strings: S1 = S1[1],…,S1[m1] S2 = S2[1],…,S2[m2] Sn = Sn[1],…,Sn[mn] Over fixed finite alphabet Σ:

13 Trie Insertion, Lookup, Deletion Time
For string: S = S[1],…,S[m] Over fixed finite alphabet Σ: O(m) Over ubounded alphabet Σ: O(m log n)

14 How do we deal with numbers?
An n-digit number is the string composed of the digits. Insertion/deletion/lookup time of number m: O(log m) Compare with AVL: O(log n)


Download ppt "The TRIE Amihood Amir."

Similar presentations


Ads by Google