Μετασχημάτισε και...

Click here to load reader

  • date post

    31-Dec-2015
  • Category

    Documents

  • view

    16
  • download

    0

Embed Size (px)

description

Μετασχημάτισε και Κυριάρχησε. Μπορούμε να επιλύσουμε ένα πρόβλημα με μετασχηματισμό σε : Ένα περισσότερο βολικό στιγμιότυπο του ιδίου προβλήματος ( απλοποίηση στιγμιότυπου ) Προταξινόμηση, Gaussian απαλοιφή , αντιστροφή πίνακα , υπολογισμός ορίζουσας - PowerPoint PPT Presentation

Transcript of Μετασχημάτισε και...

  • : ( ), Gaussian , , ( ) , , Horner, Fourier ( ) ,

    - - 4

  • - - / : (mode)

    - - 4

  • k- A[1],,A[n] : k = 1 : k = n : k = n/2 A[k] ( ): pivot A[s] s=k , A[s] sk, A[1],,A[s-1]

    - - 4

  • : (nlgn) + (1) = (nlgn) ( ): : T(n) =T(n-1) + (n+1) (n2) : (n) : T(n) =T(n/2) + (n+1) (n) Bonus: k max, min: ( ):

    - - 4

  • : (n2) : : (nlgn) : (n) : (nlgn) :

    - - 4

  • : (n2) Algorithm PresortedElementUniquenessSort the array Afor i 0 to n-2 doif A[i]=A[i+1] return falseelse return true:

    - - 4

  • (mode) : , , Algorithm PresortedModeSort the array Ai1; modefrequency0;while i n-1 dorunlength1; runvalueA[i];while i+runlengthn-1 and A[i+runlength]=runvalue runlengthrunlength+1if runlength>modefrequencymodefrequencyrunlength, modevaluerunvalueii+runlengthreturn modevalue:

    - - 4

  • Gaussian a11x + a12y = b1a21x + a22y = b2 n n ?

    - - 4

  • Gaussian (2) Ax=b Ax=b, A ( ) 2x1 - x2 + x3 = 14x1 + x2 - x3 = 5x1 + x2 + x3 = 0

    - - 4

  • Gaussian (3)Algorithm GaussEliminationfor i 1 to n do A[i,n+1]b[i]for i 1 to n-1 dofor ji+1 to n dofor ki to n+1 doA[j,k]A[j,k]-A[i,k]*A[j,i]/A[i,i]

    A[i,i] 0

    - - 4

  • Gaussian ( )Algorithm GaussElimination2for i 1 to n do A[i,n+1]b[i]for i 1 to n-1 dopivotrowifor ji+1 to n doif |A[j,i]|>|A[pivot,i]| pivotrowjfor ki to n+1 doswap(A[i,k],A[pivotrow,k])for ji+1 to n dotempA[j,i]/A[i,i]for kI to n+1 doA[j,k]A[j,k]-A[I,k]*tempEfficiency

    - - 4

  • LU of Gaussian A=LU

    LUx=b. y=Ux Ly=b Ly=b, Ux=y b

    - - 4

  • AA-1=I (singular) Gaussian . - , ? Axj=ej

    - - 4

  • n ? ? Gaussian - ?

    Cramer

    - - 4

  • AVL - ( 2-3, 2-3-4, B-)

    - - 4

  • : AVL , 1 AVL , lg n h 1.4404 lg (n + 2) - 1.3277 : 1.01 lg n + 0.1 n: : - ( 2 )

    - - 4

  • AVL :1, 2, 33, 2, 1 1, 3, 23, 1, 2 : 4, 5, 7, 2, 1, 3, 6 6.4 6.5

    - - 4

  • : R-

    - - 4

  • LR-

    - - 4

  • - - 4

  • : (heap) : :

    - - 4

  • n, n h= lg n

    - - 4

  • () ( ) 2,3

    - - 4

  • bfs () , , :

    : 2 3 6 7 5 9

    - - 4

  • : , /

    - - 4

  • bfs:

    j 2j j 2j+1 j j /2 n /2

    - - 4

  • - - 4

  • j 2j i 2(h-i) :

    2(h-i) 2i = 2 ( n lg (n + 1)) = (n)

    i=0h-1# nodes at level i

    - - 4

  • (2) : (n) ( )(logn) (n-1) 2, 3

    : (n) + ( n log n) = (n log n) (n log n)

    - - 4

  • , ,

    ::

    - - 4

  • : :

    ?

    - - 4

  • (ADT) :

    - - 4

  • Horner 19 Knuth, xp(x) = anxn + an-1xn-1 + + a1x + a0 p(x) = ( (anx + an-1) x + )x + a0 : p(x)=2x4-x3+3x2+x-5 x=3p(x) = x (x (x (2x-1) + 3) + 1) - 5

    - - 4

  • Horner (2)Algorithm Horner(P[0..n],x)// Evaluate polynomial at a given point// Input: an array P[0..n] of coefficients and a number x//Output: the value of polynomial at point xp P[n]for i n-1 down to 0 dop x*p + P[i]return p ?: p(x) (x-x0)

    - - 4

  • Horner p(x)=xn at x=a. n=blbl-1 bi b1b0n = p(x) = blxl + bl-1xl-1 + + b1x + b0 x=2Algorithm LeftRightBinaryExponentiationproduct afor i l-1 down to 0 doproduct product * productif bi1 then product product*areturn product: a13, n=13=1101

    - - 4

  • (2) an . n = bl2l + bl-12l-1 + + b12 + b0 Algorithm RightLeftBinaryExponentiationterm aif b0=1 then product aelse product 1for i 1 to l do term term * termif bi = 1 then product product * termreturn product: a13, n=13=1101

    - - 4

  • lcm(24,60)=120, lcm(11,5)=55: 24 = 2 x 2 x 2 x 3 60 = 2 x 2 x 3 x 5lcm(24,60) = (2x2x3) x 2 x 5 ( )lcm(m,n) = mn / gcd(m,n)

    - - 4

  • k>0 i j (i,j) Ak, A

    - - 4

  • : , , , ?

    - - 4

    A good place to review tree terminology and facts about height/ level etc