1 / 14

The TRIE

The TRIE. Amihood Amir . Labeled Trees. Edge Labeled Tree: T=(V,E,ℓ) Where ℓ:V  Σ , Σ is the alphabet. Example: Σ ={ A,B,C }. A. A. B. C. B. Path String.

nibaw
Télécharger la présentation

The TRIE

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

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 pathv0,…,viin 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,…,viin 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 Tof n strings S1 = S1[1],…,S1[m1] S2 = S2[1],…,S2[m2] … 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: S1[1] . . . S1[m1] $

  8. reTRIEval – inductive case (1) Assume we have defined he trie Tn of n strings. The trieTn+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 Tof 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)

More Related