??????? - PowerPoint PPT Presentation

About This Presentation
Title:

???????

Description:

- http://delab.csd.auth.gr/courses/algorithms/ - ... – PowerPoint PPT presentation

Number of Views:53
Avg rating:3.0/5.0
Slides: 39
Provided by: JohnLe181
Category:

less

Transcript and Presenter's Notes

Title: ???????


1
  • ???????µ??
  • ???????-???????? s?µß?ßasµ??
  • http//delab.csd.auth.gr/manolopo/Algorithms/

2
???????-???????? s?µß?ßasµ??
  • Se p???? p??ß??µata, ? ep?p???? ????? e???e? t??
    ???????? ep?d?se?? (extra ????? ????? ??a
    a?ap???)
  • ???s??s? e?s?d??
  • ?a????µ?s? µ? ßas?sµ??? se s?????se??
  • ?????t???? p??a?e? ???s??s?? st?? ta?t?s?
    p??t?p??
  • ???-d?µ?s?
  • ?ata?e?µat?sµ??
  • ?at?????? (p?, B-d??d?a)
  • ???a?e? µe p????f???a, ?p?? ???eta? ? d?e??as?a
  • ???aµ???? p????aµµat?sµ??

3
?a????µ?s? µe apa???µ?s?
  • Algorithm ComparisonCountSort(A0..n-1)
  • for i?0 to n-1 do Counti?0
  • for i?0 to n-2 do
  • for j?i1 to n-1 do
  • if AiltAj then Countj?Countj1
  • else Counti?Counti1
  • for i?0 to n-1 do SCounti?Ai
  • ?a??de??µa 62 31 84 96 19 47
  • ?p?d?t???t?ta

4
?a????µ?s? µe apa???µ?s? (2)
  • Algorithm DistributeCountSort(A0..n-1)
  • for j?0 to u-l do Dj?0
  • for i?0 to n-1 do DAi-l?DAi-l1
  • for j?1 to u-l do Dj?Dj-1Dj
  • for i?n-1 down to 0 do
  • j?Ai-l SDj-1?Ai Dj?Dj-1
  • ?a??de??µa 13 11 12 13 12 12
  • ?p?d?t???t?ta

5
?a?t?s? p??t?p??
  • p??t?p? string m ?a?a?t???? p??? a?a??t?s?
  • ?e?µe?? string ngtgtm ?a?a?t????, ?p?? ?a ???e?
    a?a??t?s?
  • ???????µ?? ?µ?? ß?a?
  • ??????aµµ????µe t? p??t?p? µe t?? a??? t??
    ?e?µ????
  • ?????µe??? ap? a??ste?? p??? ta de???,
    s????????µe ???e ?a?a?t??a t?? p??t?p?? µe t??
    a?t?st???? t?? ?e?µ???? µ????
  • ?a ta?t????ta? ???? ?? ?a?a?t??e? (ep?t????
    a?a??t?s?), ?
  • ?a ß?e?e? µ?a µ?-ta?t?s?
  • ?s? de? ß??s?eta? t? p??t?p? ?a? t? ?e?µe?? de?
    ??e? te?e??se?, epa?a-e?????aµµ????µe t? p??t?p?
    ?at? µ?a ??s? ?a? p??a????µe st? ß?µa 2.

6
?a?t?s? p??t?p?? ?st?????
  • 1970 ? Cook de???e? (finite-state machines) ?t?
    t? p??ß??µa µp??e? ?a ep????e? se ????? a??????
    t?? nm.
  • 1976 ? Knuth ?a? ? Pratt ß??s???? ??a? a??????µ?
    ßas?sµ??? st?? ?d?a t?? Cook. ? Morris a?e???t?ta
    ß??s?e? t?? ?d?? a??????µ? st?? p??sp??e?a ?a
    ap?f??e? t?? ep?st??f?? st? ?d?? ?e?µe??.
  • ?e??p?? t?? ?d?a pe???d? ?? Boyer ?a? Moore
    ß??s???? ??a? a??????µ? p?? e?et??e? µ??? ??a
    tµ?µa t?? ?a?a?t???? t?? ?e?µ???? st??
    pe??ss?te?e? pe??pt?se?? (s????????ta? ?a?a?t??e?
    t?? p??t?p?? ?a? t?? ?e?µ???? ap? de??? p??? ta
    a??ste??, a?t? ap? a??ste?? p??? ta de???).
  • 1980 ??a? ????? a??????µ?? t?? Rabin ?a? Karp
    p?a?t??? t???e? p??ta se ????? a?????? t?? nm,
    e?? ??e? t? p?e???-?t?µa ?t? ?e???e?eta? e????a
    st?? 2 d?ast?se?? ?a? e??a? t?s? ap??? ?s? a?t??
    t?? ?µ?? ß?a?.

7
???????µ?? Horspool
  • ???a? µ?a ap?? e?d??? t?? a??????µ?? Boyer-Moore
    (??at??ta? ta ßas???)
  • S??????e? ap? de??? p??? ta a??ste?? t???
    ?a?a?t??e? t?? p??t?p?? p??? t? ?e?µe??
  • ?????t?? e??? p??t?p??, d?µ?????e? ??a p??a?a
    ???s??s??, p?? d??e? t? µ?t?? ???s??s?? se
    pe??pt?s? µ?-ta?t?s?? (e??s??s? e?s?d??)

8
??s? µa???? ?a ???e? ? ???s??s?
  • ???p??µe t?? p??t? (de???te??) ?a?a?t??a ?e?µ????
    p?? s??????eta?
  • ? ?a?a?t??a? de? ?p???e? st? p??t?p?
  • ......c...................... (t? c de?
    ?p???e? st? p??t?p?)
  • BAOBAB
  • ? ?a?a?t??a? ?p???e? st? p??t?p? a??? ??? st?
    de???te?? ??s?
  • ........O...................... (t? O ?p???e?
    1 f??? st? p??t?p?)
  • BAOBAB
  • .......A...................... (t? A ?p???e?
    2 f???? st? p??t?p?)
  • BAOBAB
  • ? de???te??? ?a?a?t??a? p?????ese ta?t?s?
  • ........B......................
  • BAOBAB
  • ???a?a? ???s??s?? ?p????e?e? t? p????? t??
    ?a?a?t???? p?? ?a ???s??s??? µe ß?s? t?? p??t?
    s???????µe?? ?a?a?t??a

9
???a?a? ???s??s??
  • ??µ?????e?ta? sa?????ta? t? p??t?p? p??? t??
    a?a??t?s?
  • ??e? ?? ??se?? a?????p?????ta? µe t? µ???? t??
    p??t?p??
  • ???µe?????µe t? ??s? t?? ?a?a?t??a c p?? ?p???e?
    st? p??t?p? µe t?? ap?stas? t?? de???te???
    eµf???s?? t?? c ap? t? t???? t?? p??t?p??
  • Algorithm ShiftTable(P0..m-1)
  • for i?0 to size-1 do Tablei?m
  • for j?0 to m-2 do TablePj?m-1-j
  • return Table

10
???a?a? ???s??s??
  • ?a??de??µa ??a t? p??t?p? BAOBAB
  • ??te

11
???????µ?? Horspool
  • Horspool Matching(P0..m-1,T0..n-1)
  • ShiftTable(P0..m-1)
  • i?m-1
  • while iltn-1 do
  • k?0
  • while kltm-1 and Pm-1-kTi-k do
  • k?k1
  • if km return i-m1
  • else i?iTableTi
  • return -1

12
???????µ?? Horspool ?s??s?
  • ?a ß?e?e? t? pattern STING µ?sa st? text
  • A string searching example consisting of simple
    text
  • ???? e??a? ? µ??f? t?? p??a?a shift?
  • ??se? s?????se?? ?a?a?t???? ?a ???????

13
???????µ?? Boyer-Moore
  • ?as??eta? st?? ?d?e? 2 ?d?e?
  • s????????µe t??? ?a?a?t??e? t?? p??t?p?? µe t?
    ?e?µe?? ap? de??? p??? ta a??ste??
  • ded?µ???? e??? p??t?p??, d?µ?????e? ??a p??a?a
    ???s??s?? ??a t?? pe??pt?s? µ? ta?t?s?? (e??s??s?
    e?s?d??)
  • ???s?µ?p??e? ??a? ep?p???? p??a?a ???s??s??, ?
    ?p???? efa?µ??eta? a?????a µe t? p????? t??
    ?a?a?t???? p?? s?µp?pt???

14
???s??s? ?a??? s?µß????
  • ?as??eta? st?? ?d?a t?? Horspool ??a t? ???s?
    e??? ep?p???? p??a?a, ?st?s? a?t?? ? p??a?a?
    d?µ?????e?ta? d?af??et???
  • ?? ? ?a?a?t??a? c t?? ?e?µ???? p?? a?t?st???e? µe
    t?? te?e?ta?? ?a?a?t??a t?? p??t?p?? de? ?p???e?
    st? p??t?p?, t?te ???s?a????µe ?at? m ?a?a?t??e?
    (t? c e??a? ?a?? s?µß???)
  • ?? ? µ? ta?t???µe??? ?a?a?t??a? (t? ?a??
    s?µß???) de? eµfa???eta? st? p??t?p?, t?te
    ???s?a????µe ?ste ?a t?? p??spe??s??µe
  • ?? ? µ? ta?t???µe??? ?a?a?t??a? (t? ?a??
    s?µß???) eµfa???eta? st? p??t?p?, t?te
    ???s?a????µe ?ste ?a e?????aµµ?s??µe t? ?a??
    s?µß??? µe t?? ?d?? ?a?a?t??a (p?? ß??s?eta?
    a??ste?? t?? ??s?? ?p?? ?p???e µ?-ta?t?s?).

15
???s??s? ?a??? s?µß???? pa??de??µa
  • ?? ?a?? s?µß??? de? ß??s?eta? st? p??t?p?
  • ...SER......................
  • BARBER
  • BARBER ???s?a????µe 4 ??se??
  • ?? ?a?? s?µß??? ß??s?eta? st? p??t?p?
  • ...AER......................
  • BARBER
  • BARBER ???s?a????µe 2 ??se??
  • ? ???s??s? a?t? d??eta? ap? dmaxt1(c)-k,1,
    ?p?? t? t1 e??a? ? p??a?a? t?? Horspool, k e??a?
    ? ap?stas? t?? ?a??? s?µß???? ap? t? t???? t??
    p??t?p??

16
???s??s? ?a??? ep???µat?? pa??de??µa
  • ?? s?µßa??e? a? t? ta?t?sµ??? ep??eµa eµfa???eta?
    ?a? p??? st? p??t?p? (p?. ABRACADABRA)
  • ???a? s?µa?t??? ?a ß???µe ??a ???? ep??eµa µe
    d?af??et??? p??????µe?? ?a?a?t??a. ? ???s??s?
    ?s??ta? µe t?? ap?stas? µeta?? t?? d?? eµfa??se??
    t?? ep???µat??
  • ?p?s??, e??a? s?µa?t??? ?a ß???µe t? µa???te??
    p???eµa µe?????? lltk p?? ?a ta?t??eta? µe t?
    ep??eµa µ????? l. ? ???s??s? ?s??ta? µe t??
    ap?stas? µeta?? ep???µat??-p????µat??

17
???s??s? ?a??? ep???µat?? pa??de??µa (2)
K pattern d2
1 ABCBAB 2
2 ABCBAB 4
3 ABCBAB 4
4 ABCBAB 4
5 ABCBAB 4
K pattern d2
1 BAOBAB 2
2 BAOBAB 5
3 BAOBAB 5
4 BAOBAB 5
5 BAOBAB 5
18
?e????? ?a???a? t?? Boyer-Moore
  • ?p????????µe t?? ???s??s? ??
  • d1 a? k0
  • d
  • max(d1,d2) a? kgt0
  • ?p?? d1max(t1(c)-k,1)
  • ?a??de??µa


19
???????µ?? Boyer-Moore ?s??s?
  • ?a ß?e?e? t? pattern ?????? µ?sa st?
    textBESS_KNEW_ABOUT_BAOBABS
  • ???? e??a? oi p??a?e? ???s??s?? ??a t? ?a??
    s?µß??? ?a? t? ?a?? ep??eµa?
  • ??se? s?????se?? ?a?a?t???? ?a ???????

20
?ata?e?µat?sµ??
  • ???a? µ?a p??? ap?te?esµat??? µ???d?? ??a t??
    ???p???s? t?? ?e?????, d??ad? t? s????? t??
    p???e??
  • e?sa????
  • a?a??t?s?
  • d?a??af?
  • ?fa?µ????
  • p??a?e? s?µß????
  • ß?se?? ded?µ???? (e??te????? ?ata?e?µat?sµ??)

21
S??a?t?se?? ?ata?e?µat?sµ??
  • ???a?a? ?ata?e?µat?sµ?? ??a? p??a?a? µe?????? m
  • S????t?s? ?ata?e?µat?sµ?? d??e? t? ??s? t??
    p??a?a µe ß?s? t? ??e?d? k (key-to-address-transfo
    rmation)
  • ?a??de??µa ?st? ?t? ??e?d? e??a? t? SSN. ?
    s????t?s? ?ata?e?µat?sµ?? e??a?
  • h(k) k mod m
  • a? m1000, p?? ap????e?eta? t? record SSN
    315-17-4251 ?
  • ?? s??a?t?se?? ?ata?e?µat?sµ?? p??pe?
  • ?a ?p????????ta? e????a
  • ?a ?ata??µ??? ta ??e?d?? ?µ???µ??fa se ??? t??
    p??a?a

22
S??????se??
  • ?? h(k1)h(k2), t?te ?p???e? s??????s?
  • ??a ?a?? s????t?s? p???a?e? ????te?e? s??????se??
  • ?? s??????se?? de? µp????? ?a e?a?e?f????
    (pa??d??? t?? ?e?e?????)
  • ?? s??????se?? ?????ta? µe d?? t??p???
  • ?????t?? ?ata?e?µat?sµ?? ???e ??s? t?? p??a?a
    de???e? se µ?a ??sta µe ??a ta ??e?d?? p??
    ?????ta? se a?t? t? ??s?
  • ??e?st?? ?ata?e?µat?sµ?? ??a ??e?d? a?? ??s?,
    se pe??pt?s? s??????s??, ß?e? ??a ???? ??s? ??a
    t? ??? ??e?d?
  • G?aµµ??? a?a??t?s? p??a??e st?? ep?µe?? ??s?
  • ??p??? ?ata?e?µat?sµ?? ???s?µ?p???se µ?a ????
    s????t?s? ?ata?e?µat?sµ?? ??a ?a ß?e?? t? ??µa

23
?a??d??? ?e?e?????
  • ?p??????ta? 23 t??a?a ?t?µa. ???? e??a? ?
    p??a??t?ta 2 e? a?t?? ?a ????? t?? ?d?a ?µ??a
    ?e?????a?
  • P(A) ? ??t??µe?? p??a??t?ta
  • P(A) 1-P(A)
  • P(A) ?p??????eta? ?e????ta? ?t? 2?? de? ??e? t??
    ?d?a ?µ??a ?e?????a µe t?? p??t?, ? 3?? de? ??e?
    t?? ?d?a µ??a ?e?????a µe t?? 1? ?a? t?? 2? ... ?
    23?? de? ??e? t?? ?d?a µ??a ?e?????a µe t?? 1?,
    t?? 2?, t?? 3?, ... t?? 22?.
  • P(A)(365/365)x(364/365)xx(343/365)0.493
  • P(A)0.507

24
?????t?? ?ata?e?µat?sµ??
  • ?a ??e?d?? ap????e???ta? se ??ste? ??? ap? t??
    p??a?a ?ata?e?µat?sµ??, p?? pe????e? µ??? t??
    ????f?? t?? ??st??.
  • ?a??de??µa A, FOOL, AND, HIS, MONEY, ARE, SOON,
    PARTED
  • h(K) ?????sµa t?? ??se?? t?? ??aµµ?t?? t?? K
    MOD 13

Key A FOOL AND HIS MONEY ARE SOON PARTED
h(K) 1 9 6 10 7 11 11 12
12
11
10
9
8
7
6
5
4
3
2
1
0

A
FOOL
AND
HIS
MONEY
ARE
PARTED
SOON
25
?????t?? ?ata?e?µat?sµ??
  • ?? ? s????t?s? ?ata?e?µat?sµ?? ?ata??µe? ta
    ??e?d?? ?µ???µ??fa, t? µ?s? µ???? t?? ??sta?
    e??a? an/m (apa?????ta? f??t?s??)
  • ?? µ?s? p????? t?? s?????se?? e??a? S1a/2,
    U1a
  • ? ?e???te?? pe??pt?s? e??a? ??aµµ???!
  • ? a????t?? ?ata?e?µat?sµ?? ?e?t????e? a??µ? ?a?
    a? ngtm

26
??e?st?? ?ata?e?µat?sµ??
  • ?a ??e?d?? ap????e???ta? µ?sa st?? p??a?a
    ?ata?e?µat?sµ??.

Key A FOOL AND HIS MONEY ARE SOON PARTED
h(K) 1 9 6 10 7 11 11 12
0
1
2
3
4
5
6
7
8
9
10
11
12
A
A FOOL
A AND FOOL
A AND FOOL HIS
A AND MONEY FOOL HIS
A AND MONEY FOOL HIS ARE
A AND MONEY FOOL HIS ARE SOON
PARTED A AND MONEY FOOL HIS ARE SOON
27
G?aµµ??? a?a??t?s?
  • ?e? ?e?t????e? a? ngtm ?a? ap?fe??e? t??? de??te?
  • ?? d?a??af?? de? e??a? ?µese?
  • ?? p????? t?? s?????se?? ??a µ?a e?sa????/
    a?a??t?s?/ d?a??af? e??? ??e?d??? e?a?t?ta? ap?
    t? a (pa?????ta f??t?s??)
  • ep?t???? a?a??t?s? (½) (1 1/(1- a))
  • a?ep?t???? a?a??t?s? (½) (1 1/(1- a)²)
  • ?a??? ?eµ??e? ? p??a?a? (a?1), t? p????? t??
    s?????se?? a????e? d?aµat???

28
??p??? ?ata?e?µat?sµ??
  • ?ta? a????e? t? a, d?µ????????ta? s?ss?µat?se??
    (clusters)
  • ??t? ep?de????e? t?? ep?d?s? d?aµat???.
  • G?a t? ???? a?t? se pe??pt?s? s??????s??
    ???s?µ?p??e?ta? µ?a de?te?? s????t?s?
    ?ata?e?µat?sµ??, p?? d??e? t? µ??e??? t??
    ??µat?? ??a t?? ep?µe?? ??s? ?? s????t?s? t??
    t?µ?? t?? ??e?d???
  • G?a pa??de??µa s(k) (key/m) mod m s(k) m
    2 k mod(m-2), s(k) 8 k mod 8 s(k)
    k mod 97 1
  • ?p?de????eta? ?t? S ln(1-a) / a U 1/(1-a)

29
?ata?e?µat?sµ?? e??te?????
  • ??afe??µaste st?? pe??pt?s? p?? ta ded?µ??a de?
    ?????? st?? ????a µ??µ?
  • S??ep?? ???a?????µe a??e?? st? de?te?e???sa µ??µ?
  • Se ???e d?e????s? a?t?st???e? ??a? ??d?? (disk
    page, block) µe ????t???t?ta µe?a??te?? t??
    µ???da?
  • ?fa?µ??eta? se ß?se?? ded?µ????

30
????t?? ??a ?-d??d?a
  • ?st? ?t? ?????µe ?a ap????e?s??µe 20 e?at?µ???a
    st???e?a se ??a AVL d??d??
  • ?? ???? t?? d??d??? ?a e??a? log2 20,000,000 is
    about 24.
  • ? ??s? e??a? ?a ????µe pe??ss?te?a pa?d?? a??
    ??µß? ?ste ?a µe???e? t? ????.

31
???sµ?? ?-d??d???
  • ??a? ?-d??d?? t???? m ??e? ta e???
    ?a?a?t???st???
  • ?a f???a e??a? st? ?d? ?ep?ped?
  • ???e es?te????? ??µß?? ??e? ap? ?m/2? µ???? m
    pad??
  • ? ???a ??e? ap? 2 µ???? m pa?d??.
  • ??a? es?te????? ??µß?? µe k ??e?d??, ??e? k1
    pa?d??

32
?a??de??µa B-d??d???
??µ?µ? ?-d??d?? t???? 5 µe 26 ??e?d??
26
6
12
51
62
42
1
2
4
7
8
13
15
18
25
55
60
70
64
90
45
27
29
46
48
53
33
??sa???? se ?-d??d??
  • ???s???µe t? f???? ?p?? ?a ???e? ? e?sa????.
  • ?? ?p???e? ?????, t?te t? ??e?d? e?s??eta?
  • ?? de? ?p???e? ?????, t?te t? f???? d?asp?ta? ?a?
    t? µesa?? ??e?d? a????eta? st? a??te?? ep?ped?
  • ?? t? a?e???µe?? ??e?d? ????e? st?? pat????
    ??µß?, t?te a?t? e?s???eta? se a?t?? t?? pat????
    ??µß?
  • ?? t? a?e???µe?? ??e?d? de? ????e? st?? pat????
    ??µß?, t?te ? pat????? ??µß?? d?asp?ta?
  • ?ts? ?? d?asp?se?? pat????? ??µß?? µp??e? ?a
    ft?se? µ???? t? ???a.

34
?a??de??µa e?sa?????
  • Se ??a ?-d??d?? t???? 5 p???e?ta? ?a e?sa????? ta
    ??e?d?? 1 12 8 2 25 5 14 28 17 7 52
    16 48 68 3 26 29 53 55 45
  • ? e?sa???? t?? 1, 12, 8, 2 d??e?
  • ? e?sa???? t?? 25 d??e?
  • ? e?sa???? t?? 5, 14, 28 d??e?
  • ? e?sa???? t?? 17 d??e?

35
?a??de??µa e?sa????? (2)
  • Se ??a ?-d??d?? t???? 5 p???e?ta? ?a e?sa????? ta
    ??e?d?? 1 12 8 2 25 5 14 28 17 7 52
    16 48 68 3 26 29 53 55 45
  • ? e?sa???? t?? 7, 52, 16, 48, d??e?
  • ? te???? µ??f? e??a?

36
??a??af? ap? ?-d??d??
  • ?p?? ?? e?sa????? ?ate??????ta? sta f???a, ?a? ??
    d?a??af?? s?µßa????? sta f???a.
  • ??a??????ta? ?? e??? pe??pt?se??
  • ?? ?p? d?a??af? ??e?d? ß??s?eta? se f???? ?a?
    d?a??af?µe?? af??e? t? f???? se ??µ?µ? ?at?stas?.
  • ?? ?p? d?a??af? ??e?d? ß??s?eta? se es?te????
    ??µß?. ??te ? ??s? t?? ?ata?aß??eta? ap? t?
    aµ?s?? µe?a??-te??/µ????te??. ?ts? t? p??ß??µa
    µetaf??eta? se f????.
  • ?? t? f???? µ??e? µe ????te?? pe??e??µe??, t?te
  • ?????eta? a? µp??e? ?a da?e?se? ??p????
    ?e?t?????? ??µß?? (key redistribution)
  • ?? de? µp??e? ?a da??se? ??p???? ?e?t??????
    ??µß??, t?te ??e?ta? s?????e?s? ??µß?? (node
    merging)

37
?a??de??µa d?a??af??
  • ?p? t? ?-d??d?? t???? 5 ?a ?????? d?ad?????
    d?a??af??
  • ??a??af? 52

38
?a??de??µa d?a??af?? (2)
  • ??a??af? 72
  • ??a??af? 22
Write a Comment
User Comments (0)
About PowerShow.com