approximate pattern matching using suffix tries
play

Approximate Pattern Matching Using Suffix Tries Hendrik Nigul - PowerPoint PPT Presentation

Approximate Pattern Matching Using Suffix Tries Hendrik Nigul nigulh@math.ut.ee University of Tartu Veskisilla, Oct 3 2004 p. 1 Overview Introduction, problem description Suffix tries What is a suffix trie How to create suffix tries


  1. Approximate Pattern Matching Using Suffix Tries Hendrik Nigul nigulh@math.ut.ee University of Tartu Veskisilla, Oct 3 2004 – p. 1

  2. Overview Introduction, problem description Suffix tries What is a suffix trie How to create suffix tries How to use suffix tries Algorithms with suffix tries Exact string matching Approximate string matching Exact all-against-all matching Approximate all-against-all matching Results Conclusions Veskisilla, Oct 3 2004 – p. 2

  3. Introduction Problem statement: Given text T = t 1 t 2 . . . t n and pattern P = p 1 p 2 . . . p m , find all occurrences of P in T . By an occurrence we mean a position i , such that t i +1 = p 1 , t i +2 = p 2 , . . . , t i + m = p m Veskisilla, Oct 3 2004 – p. 3

  4. Introduction Problem statement: Given text T = t 1 t 2 . . . t n and pattern P = p 1 p 2 . . . p m , find all occurrences of P in T . By an occurrence we mean a position i , such that t i +1 = p 1 , t i +2 = p 2 , . . . , t i + m = p m Sometimes we have have several patterns: Find occurrences of BANANA in text T Find occurrences of ANANAS in text T . . . Veskisilla, Oct 3 2004 – p. 3

  5. Introduction Sometimes we accept approximate matches: Find occurrences of BANANA , but also accept MANANA , BANAANA , BAANA , etc. If we make several queries, we should preprocess our text. We use suffix tries. Veskisilla, Oct 3 2004 – p. 4

  6. Suffix trie : Example: Create suffix trie for text BANANA A B N $ N $ A A A N N $ : N $ A A A BANANA$ NA $ A N $ NA $ NA$ $ $ A NA$ $ $ Suffix tree Suffix trie Veskisilla, Oct 3 2004 – p. 5

  7. Indexing All suffixes are added to the trie one by one. : : : B A B A B N A N A N A A N A N A N N A N A N $ A A N A N A N $ A $ A $ A $ $ $ Inserting Inserting Inserting NANA$ and BANANA$ ANANA$ ANA$ Veskisilla, Oct 3 2004 – p. 6

  8. Outputting index to a file We want to use the index many times. We want to write it into a file. Later we must be able to read that trie from file. We output the trie in prefix order, i.e. we output a node first, and then its children. We need to calculate the size of each node, that is the number of bytes of the description of the subtree rooted with that node Veskisilla, Oct 3 2004 – p. 7

  9. Outputting index to a file : Suffix trie for BANANA contains suffixes A B N $ BANANA$ N $ A A ANANA$ NANA$ A N N $ ANA$ N $ A A NA$ A$ A N $ $ $ A $ Veskisilla, Oct 3 2004 – p. 8

  10. Outputting index to a file The suffix trie for BANANA : $ $ $ $ A N A N A B A N A N A 55 19 14 11 6 4 2 2 2 17 14 11 8 6 4 2 N A N A $ $ $ 14 11 6 4 2 2 2 The index written to a file :55A19N14A11N6A4$2$2$2B17A14N11A8N6A4$2 N14A11N6A4$2$2$2 Veskisilla, Oct 3 2004 – p. 9

  11. Introducing pointers The size of a trie : : for string of length A B N $ A @ N @ n is O ( n 2 ) . N $ A A N @ A Indexing of an 1 MB textfile would A N N $ A @ @ be impractical. N $ A A @ @ We will use the same idea as in A N $ suffix trees – group $ A nodes with a single child. Here we only $ group nodes with a Trie with Trie before single leaf child. pointers Veskisilla, Oct 3 2004 – p. 10

  12. Outputting index with pointers Input string BANANA$ 0123456 Suffix trie with pointers : @ @ @ @ @ @ @ A N A N A 28 13 8 6 4 6 6 0 8 6 4 6 6 Suffix trie in file :28A13N8A6@4@6@6@0N8A6@4@6@6 In order to read suffix trie from file, we need the original input Veskisilla, Oct 3 2004 – p. 11

  13. Indexing Sometimes we have data consisting of several items. We can make suffix trie for many strings. Later we can use the index to search patterns from all the strings simultanously. Veskisilla, Oct 3 2004 – p. 12

  14. Size of index Index size / text size ratio Length of row Length of row No. of No. of rows 10 100 1000 rows 10 100 1000 10000 1 12.9 163 2223 1 3.55 5.14 6.01 7.11 10 9.73 157 2214 10 4.28 5.95 7.10 8.11 100 6.94 152 100 5.21 6.97 8.09 9.13 1000 4.93 146 1000 5.92 7.93 9.11 10000 3.54 10000 6.65 8.92 without pointers with pointers If a random string in 4-letter alphabet has length n , then the number of nodes is about 1 . 72 n . The description of each node is at most 1 + log 10 n bytes. Veskisilla, Oct 3 2004 – p. 13

  15. Using the index Suppose we have an suffix trie S for text T written to a file. The two operations that can be performed for any node: Get the next sibling of that node Get the first child of that node :55A19N14A11N6A4$2$2$2B17A14N11A8N6A4$2 N14A11N6A4$2$2$2 How can we walk through the trie? Veskisilla, Oct 3 2004 – p. 14

  16. Walking through the trie : : A B N $ N $ A A A N N $ N $ A A A N $ $ A $ :55A19N14A11N6A4$2$2$2B17A14N11A8N6A4$2N14A11N6A4$2$2$2 Veskisilla, Oct 3 2004 – p. 15

  17. Walking through the trie : : A A B N $ N $ A A A N N $ N $ A A A N $ $ A $ :55A19N14A11N6A4$2$2$2B17A14N11A8N6A4$2N14A11N6A4$2$2$2 Veskisilla, Oct 3 2004 – p. 15

  18. Walking through the trie : : A A B N $ N N $ A A A A N N $ N $ A A A N $ $ A $ :55A19N14A11N6A4$2$2$2B17A14N11A8N6A4$2N14A11N6A4$2$2$2 Veskisilla, Oct 3 2004 – p. 15

  19. Walking through the trie : : A A B N $ N N $ A A A A N N $ N N $ A A A N $ $ A $ :55A19N14A11N6A4$2$2$2B17A14N11A8N6A4$2N14A11N6A4$2$2$2 Veskisilla, Oct 3 2004 – p. 15

  20. Walking through the trie : : A A B N $ N N $ A A A A N N $ N $ A A A N $ $ A $ :55A19N14A11N6A4$2$2$2B17A14N11A8N6A4$2N14A11N6A4$2$2$2 Veskisilla, Oct 3 2004 – p. 15

  21. Walking through the trie : : A A B N $ N N $ A A A A N N $ N $ A A A N $ $ A $ :55A19N14A11N6A4$2$2$2B17A14N11A8N6A4$2N14A11N6A4$2$2$2 Veskisilla, Oct 3 2004 – p. 15

  22. Walking through the trie : : A A B N $ N $ A A A N N $ N $ A A A N $ $ A $ :55A19N14A11N6A4$2$2$2B17A14N11A8N6A4$2N14A11N6A4$2$2$2 Veskisilla, Oct 3 2004 – p. 15

  23. Walking through the trie : : A B B N $ N $ A A A N N $ N $ A A A N $ $ A $ :55A19N14A11N6A4$2$2$2B17A14N11A8N6A4$2N14A11N6A4$2$2$2 Veskisilla, Oct 3 2004 – p. 15

  24. Walking through the trie : : A B B N $ N $ A A A A N N N $ N $ A A A A N $ $ A $ :55A19N14A11N6A4$2$2$2B17A14N11A8N6A4$2N14A11N6A4$2$2$2 Veskisilla, Oct 3 2004 – p. 15

  25. Walking through the trie : : A B B N $ N $ A A A A A N N N $ N $ A A A A N $ $ A $ :55A19N14A11N6A4$2$2$2B17A14N11A8N6A4$2N14A11N6A4$2$2$2 Veskisilla, Oct 3 2004 – p. 15

  26. Walking through the trie : : A B N N $ N $ A A A N N $ N $ A A A N $ $ A $ :55A19N14A11N6A4$2$2$2B17A14N11A8N6A4$2N14A11N6A4$2$2$2 Veskisilla, Oct 3 2004 – p. 15

  27. Walking through the trie : : A B N N $ N $ A A A A N N $ N $ A A A N $ $ A $ :55A19N14A11N6A4$2$2$2B17A14N11A8N6A4$2N14A11N6A4$2$2$2 Veskisilla, Oct 3 2004 – p. 15

  28. Walking through the trie : : A B N $ N $ A A A N N $ N $ A A A N $ $ A $ :55A19N14A11N6A4$2$2$2B17A14N11A8N6A4$2N14A11N6A4$2$2$2 Veskisilla, Oct 3 2004 – p. 15

  29. Algorithms with tries We now show how to use tries. Suffix tries can be used in the same way. Veskisilla, Oct 3 2004 – p. 16

  30. Exact string matching Example. We have an index containing strings: ALGO ANGLO ANGOLA ANGO GO MANGO We want to search for occurrences of string ANGO Veskisilla, Oct 3 2004 – p. 17

  31. Exact string matching : Trie containig strings: A G M ALGO ANGLO L N O A ANGOLA ANGO G G $ N GO O L O G MANGO $ O L $ O $ A $ $ Veskisilla, Oct 3 2004 – p. 18

  32. Exact string matching : : Searching for string ANGO A G M Search table char OK L N O A + G G $ N A N O L O G G $ O L $ O O $ A $ $ Veskisilla, Oct 3 2004 – p. 18

  33. Exact string matching : : Searching for string ANGO A A G M Search table char OK L N O A + G G $ N + A N O L O G G $ O L $ O O $ A $ $ Veskisilla, Oct 3 2004 – p. 18

  34. Exact string matching : : Searching for string ANGO A A G M Search table char OK L L N O A + G G $ N + A - N O L O G G $ O L $ O O $ A $ $ Veskisilla, Oct 3 2004 – p. 18

  35. Exact string matching : : Searching for string ANGO A A G M Search table char OK L N N O A + G G $ N + A + N O L O G G $ O L $ O O $ A $ $ Veskisilla, Oct 3 2004 – p. 18

  36. Exact string matching : : Searching for string ANGO A A G M Search table char OK L N N O A + G G G $ N + A + N O L O G + G $ O L $ O O $ A $ $ Veskisilla, Oct 3 2004 – p. 18

  37. Exact string matching : : Searching for string ANGO A A G M Search table char OK L N N O A + G G G $ N + A + N O L L O G + G $ O L $ O - O $ A $ $ Veskisilla, Oct 3 2004 – p. 18

  38. Exact string matching : : Searching for string ANGO A A G M Search table char OK L N N O A + G G G $ N + A + N O L O O G + G $ O L $ O + O $ A $ $ Veskisilla, Oct 3 2004 – p. 18

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend