BruteForce a ed ats - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

BruteForce a ed ats

Description:

Se a?t? t?? ?at?????a e p?pt??? ???? ?? a?????? ?? ?? ?p???? p??????? ape??e?a? ... xm=x0 i*d; ym= y0 j*e; return min, xm, ym; ... – PowerPoint PPT presentation

Number of Views:30
Avg rating:3.0/5.0
Slides: 23
Provided by: christosp1
Category:

less

Transcript and Presenter's Notes

Title: BruteForce a ed ats


1
???????µ?? Brute-Force ?a? ??e??d??? ??a??t?s?
2
?e??????
  • ???????µ?? t?p?? Brute-Force
  • ?a?ade??µata
  • ??a??t?s??
  • ?a????µ?s??
  • ???s??ste?a s?µe?a
  • Convex hull
  • ?e?t?st?p???s?
  • Knapsack problem
  • ???ß??µata ????es?? (Assignment)

3
???????µ?? Brute-Force
  • Se a?t? t?? ?at?????a eµp?pt??? ???? ??
    a??????µ?? ?? ?p???? p??????? ape??e?a? ap? t?
    d?at?p?s? t?? p??ß??µat?? ?a? t?? ???sµ? t??
    d?af???? e?????? p?? s??ep????ta? ap? t? f?s?
    t?? p??ß??µat??.
  • ????? Ge???? ????d??
  • ?a p?e?sta p??ß??µata µe ??s? ????? µ?a ??s? p??
    eµp?pte? se a?t? t?? ?at?????a
  • ?p??e? ?a e??a? p??? ?a?? ?a? p?a?t??? µ???d??
    ??a p??ß??µata p?? ? e?s?d?? e??a? µ????? ?
    µesa??? µe??????.

4
???ß??µata ??a??t?s??
  • ??s?d?? ??sta A0,,n-1, ??e?d? ?
  • ???d?? ? ??s? t?? ??e?d??? st? ??sta (e??
    ?p???e?)

Search(A, K) i0 While iltn and Ai!
K ii1 If iltn return i return -1
Search2(A, K) i0 An K While Ai!
K ii1 If iltn return i return -1
  • ?a??te?? ?e??pt?s?
  • ?e???te?? ?e??pt?s?

5
???ß??µata ?a????µ?s??
  • ??s?d?? ??sta A0,,n-1
  • ???d?? ?a????µ?µ??? ??sta A0,,n-1

sort(A) for i0 to n-2 min i for ji1
to n-1 if Aj lt Amin min
j swap(Ai,Amin)
6
Selection Sort
sort(A0n-1) for i0 to n-2 min i for
ji1 to n-1 if Aj lt Amin min
j swap(Ai,Amin)
7
?p?d?s? Selection Sort
sort(A0n-1) for i0 to n-2 min i for
ji1 to n-1 if Aj lt Amin min
j swap(Ai,Amin)
  • ?? ?a ?p?????s??µe
  • ?a??te??, ?e???te?? ? µ?s? pe??pt?s?

8
??a??t?s? se???? ?a?a?t???? (string)
  • ??s?d?? ??ste? T0,,n-1, s0,,k-1, kltn
  • ???d?? T?s? st?? ?p??a eµfa???eta? t? s st?? T

stringMatch(T0n-1,s0k) for i0 to
n-k j0 while sjTij jj1 if jk
return i return -1
  • ?e???te?? pe??pt?s?

9
???ß??µa e??es?? t?? d?? p??s??ste??? s?µe???
  • ?ed?µ???? µ?a? ??sta? µe n s?µe?a P0,,Pn-1
    ß?e?te p??a d?? s?µe?a ????? t?? µ????te??
    ap?stas?.
  • ?p?stas? µeta?? d?? s?µe??? se ???? D d?ast?se??
  • G?a pa??de??µa se d?sd??stat? ????,

10
???s??ste?a S?µe?a
ClosestPoints(P0n-1) dmin infinity for i0
to n-2 for ji1 to n-1 d
sqrt((x0-x1)2(y0-y1)2) if d lt dmin
dmin d p1i, p2j return p1, p2
11
???ß??µa e??es?? t?? ???t?? ????? p??
eµpe????e?e? ??a s????? ap? s?µe?a
  • ???t?? (convex) ?????
  • ??a? ????? e??a? ???t?? e?? ??a ???e d?? s?µe?a
    p?? a?????? st?? ????, ??a ta s?µe?a p??
    ß??s???ta? st? tµ?µa t?? e??e?a? p?? e???e? ta
    d?? s?µe?a a???e? ep?s?? st?? ????
  • G?a pa??de??µa se d?sd??stat? ????,

12
???ß??µa e??es?? t?? ???t?? ????? p??
eµpe????e?e? ??a s????? ap? s?µe?a
  • ?ed?µ???? µ?a? ??sta? µe n s?µe?a P1,,Pn
    ß?e?te t? µ????te?? ???t? ???? p?? eµpe????e?e?
    ??a ta s?µe?a P1,,Pn (convex hull).
  • Te???µa ?? convex hull e??? s?????? ap? s?µe?a
    P1,,Pn (ngt2) e??a? ??a p??????? t?? ?p???? ??
    ????e? e??a? ??p??? ap? ta s?µe?a t?? s??????
    P1,,Pn.
  • G?a pa??de??µa se d?sd??stat? ????,

13
Convex Hull
ConvexHall(P1n) for i1 to n-1 for ji1 to
n-1 k1 PgetNextPoint while
(kltn-2) and kk1 PgetNextPoint
if kn-2 (Pi,Pj) on boundary
14
Ge?µet??a
15
?e?t?st?p???s?
  • ??ste t? p?? ??t? p??ß??µa ße?t?st?p???s??

16
?e?t?st?p???s?
minimize(f,x0,x1,y0,y1,n) d(x1-x0)/(n-1) e(y1
-y0)/(n-1) min infinity for i0 to n-1 for
j0 to n-1 if f(x0id, y0je)ltmin min
f(x0id, y0je) xmx0id ym
y0je return min, xm, ym
17
???ß??µa t?? ?e???de??? ????t? (Traveling
Salesman Problem (TSP))
  • ??a? p???t?? ???e? ?a ep?s?efte? n p??e?? ?a? ?a
    ep?st???e? st? s?µe?? ap? ?p?? ?e????se µe t? p??
    ??????? t??p?.
  • ?e? p??pe? ?a ep?s?efte? µ?a p??? pe??ss?te?e?
    ap? µ?a f????
  • ??e?te t? p?? s??t?µ? Hamiltonian Circuit.
  • Hamiltonian Circuit e??a? ??a µ???p?t? t? ?p???
    ep?s??pteta? ????? t??? ??µß??? t?? ???f?? ap?
    µ?a f??? ?a? ep?st??fe? st? s?µe?? ap? ?p??
    ?e????se.

18
???ß??µa t?? ?e???de??? ????t? (Traveling
Salesman Problem (TSP))
  • ???ste ??a ta p??a?? µ???p?t?a
  • ??at?ste e?e??? µe t? ?aµ???te?? ??st??

19
Knapsack Problem
  • ??a? ??e?ß?t?? p????aµµat??e? t?? ep?µe?? t??
    pe??p?te?a. St? sa??d?? t?? µp??e? ?a µetaf??e?
    µ???? n ????.
  • ?p?????? m a?t??e?µe?a ta ?p??a µp??e? ?a t??
    ???s?µe?s???
  • ???e a?t??e?µe?? ?????e? wi ????
  • ? ???s?µ?t?ta t?? ???e a?t??e?µ???? d??eta? ap?
    ??a de??t? yi.
  • ?????ste t?? ??e?ß?t? ?a ß?e? p?? ?a ?eµ?se? t?
    sa??d?? t?? ?ts? ?ste ?a µe??st?p???se? t?
    s??????? ???s?µ?t?ta ???? t?? a?t??e?µ???? p??
    ?a p??e? µa?? t??.
  • ?a?ade??µata sta ?p??a t? p?? p??? p??ß??µa
    efa?µ??e?

20
Knapsack Problem ?a??de??µa
  • ?? sa??d?? µp??e? ?a ????se? 10 ????
  • ?p?????? 4 a?t??e?µe?a
  • ????? 7, ???s?µ?t?ta 42
  • ????? 3, ???s?µ?t?ta 12
  • ????? 4, ???s?µ?t?ta 40
  • ????? 5, ???s?µ?t?ta 25
  • ???? ?? p??a??? s??d?asµ??

21
???ß??µa ????es?? (Assignment)
  • ?p?????? n f??t?t?? ?a? n p??ß??µata. G?a t??
    ?a??te?? ?ata??µ? t?? f??t?? e??as?a? ? ???e
    f??t?t?? ?a ??se? ??a ap? ta p??ß??µata.
  • ??? ? f??t?t?? i ep??e???se? t? p??ß??µa j t?te
    ?a p??e? bij ßa?µ???
  • ??? p??pe? ?a ?ata?eµ????? ta p??ß??µata ?ts?
    ?ste ?a µe??st?p????e? ? ßa?µ?? ????????? t??
    t????
  • ???a pa?ade??µata sta ?p??a efa?µ??e? a?t? t?
    p??ß??µa

22
?a??de??µa ???ß??µat?? ????es??
  • ?p???ste p?? ?p?????? 4 f??t?t?? ?a? 4 p??ß??µata
    ?a? ?? ßa?µ?? fa????ta? p?? ??t?.
  • ?? d????sµa f1, f2, f3, f4 a?t?p??s?pe?e? t?
    f??t?t? p?? ?a ??se? t? p??ß??µa 1, 2, 3, ?a? 4
    a?t?st???a
  • ??e?te ??e? t?? p??a??? a?a??se?? (permutations)
    ?a? ?p?????ste t? s??????? ßa?µ?
  • ??se? ?? p??a??? a?a??se?? ?p??????
Write a Comment
User Comments (0)
About PowerShow.com