ΠΛΗ30 ΜΑΘΗΜΑ 1.1

Click here to load reader

  • date post

    19-Aug-2015
  • Category

    Education

  • view

    246
  • download

    0

Embed Size (px)

Transcript of ΠΛΗ30 ΜΑΘΗΜΑ 1.1

  1. 1. 30 1: 1.1:
  2. 2. . . 1. 2. 3. 1. 2 , 30, 1.1: 2. 3. 4. . 1. 2. (.) 3. .
  3. 3. . 3 , 30, 1.1: , , (-)
  4. 4. . 1. , : ( ) ( 30 ) ( ) 4 , 30, 1.1: ( ) : : : : [5, 8, 9, 11, 14] [4,12,7,9] : [5, 8, 9, 11, 14],11 [3,6,9,14,17],12 : InsertionSort, BubbleSort, SelectionSort, MergeSort, QuickSort : LinearSearch, BinarySearch : [5, 8, 9, 11, 14] [4,7,9,12] : NAI -
  5. 5. . 2. , : : for, while, dowhile : ifelse ifelse 5 , 30, 1.1: ( .. +,-,*,/,mod) ( )
  6. 6. . 3. 1. . . : 6 , 30, 1.1: : SelectionSort : LinearSearch : (, ) . ( )T n n= 2 ( ) 3T n n n= +
  7. 7. . 3. 1. ( LinearSearch) ( Linear Search) 7 , 30, 1.1: procedure LinearSearch(A,x) for i=1 to n if (A[i]==x) A n , x. . return end if end for return end procedure
  8. 8. . 3. 1. ( LinearSearch) : ( ). , , : 8 , 30, 1.1: ( ). , : . . 1 ( ) 1 n i T n n = = = ( ) 1T n =
  9. 9. . 3. 1. ( SelectionSort) ( SelectionSort) 9 , 30, 1.1: procedure SelectionSort(A) for i=1 to n pos=i for j=i+1 to n if (A[j]
  10. 10. . 3. 1. (O SelectionSort) ( ) , - . . .. [4 3 5 1 2] : 10 , 30, 1.1: 1 2 3 4 5 1 2 3 4 5 1: 4: 4 3 5 1 2 1 2 3 4 5 1 3 5 4 2 1 2 3 4 5 1 2 5 4 3 1 2 3 4 5 1: 2: 3: 4: 5: : 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5
  11. 11. . 3. 1. (O SelectionSort) . ( if) ( ). : 11 , 30, 1.1: 1 1 ( ) [1 ( 2) 3] n n i j i T n = = + = + + = 1 1 1 1 1 1 1 1 1 1 2 2 1 2 [4 2( 1)] [4 2( ( 1) 1)] [4 2( )] [4 2 2 ] 4 (2 ) (2 ) ( 1) 4 2 2 4 2 2 2 3 i j i n n i j i n i n i n i n n n i i i n i n i n i n i n i n n n n i n n n n = = + = = + = = = = = = = = + = = + + + = = + = = + = = + = + = + = + = = +
  12. 12. . 3. 1. (O SelectionSort) . , if. : 12 , 30, 1.1: ( ) [1 ( 1) 3] n n T n = + + = 1 1 1 1 1 1 1 1 2 2 1 2 ( ) [1 ( 1) 3] [4 ( ( 1) 1)] [4 ] [4 ] 4 ( ) ( ) ( 1) 4 4 2 0.5 2.5 n n i j i n i n i n i n n n i i i n i T n n i n i n i n i n n n n i n n n n = = + = = = = = = = = + + = = + + + = = + = = + = = + = + = + = + = = +
  13. 13. . 3. 2. : LinearSearch . SelectionSort . 13 , 30, 1.1: : . (.)
  14. 14. . 3. 2. : : LinearSearch : : : 14 , 30, 1.1: ( )n n = )()( nn = : LinearSearch : : : SelectionSort : : : SelectionSort : : : )()( nn = ( ) 1n = )1()( = n 2 ( ) 3n n n = + 2 ( ) 0.5 2.5n n n = + )()( 2 nn = )()( 2 nn =
  15. 15. . 3. 2. ; : : 15 , 30, 1.1: < < < < : n. : : k >0 : k >0 : a >1 : )()( k nn = )()( n an = )(log)( nn k = )!()( nn = )()( n nn = n nn
  16. 16. . 3. 3. . . 16 , 30, 1.1: ! n, n . (.) .
  17. 17. . 3. 3. ( Fibonacci) : Fibonacci : 17 , 30, 1.1: = = = 2,1 1,1 n n fn n- . >+ 2,21 nff nn n 1 2 3 4 5 6 7 8 9 10 1 1 2 3 5 8 13 21 34 55 ...
  18. 18. . 3. 3. ( Fibonacci) n- Fibonacci : 18 , 30, 1.1: procedure Fibonacci(n) A[1]=1 A[2]=1 for i=3 to n A[i]=A[i-1]+A[i-2] : n A n i T(n)=n+2 T(n)=(n) A[i]=A[i-1]+A[i-2] end for return A[n] end procedure
  19. 19. . 3. 3. ( Fibonacci) ; 19 , 30, 1.1: procedure Fibonacci(n) if (n=1) return 1 else if (n=2) return 1 else a=1 : i,n,a,b,c T(n)=5 T(n)=(1) a=1 b=1 for (i=3 to n) c=a+b a=b b=c end for end if return c end procedure
  20. 20. . 3. 4. . : ( (.) ) . . 20 , 30, 1.1: . : ./ ./ LinearSearch (1) ? (n) BinarySearch (1) ? (log n) BubbleSort (n2) (n2) (n2) InsertionSort (n) ? (n2) SelectionSort (n2) (n2) (n2) MergeSort (n logn) (n logn) (n logn) QuickSort (n logn) (n logn) (n2)
  21. 21. . 1. 1. : 21 , 30, 1.1: .... ++ ....
  22. 22. . 1. 2. for for for for. ..: 22 , 30, 1.1: ..: for (i=A to B) : for (i=A to B) ... K ... end for = = B Ai KnT )( = += B Ai 11 = += n i nni 1 2/)1( = ++= n i nnni 1 2 6/)12)(1( = + = n i n i x x x 0 1 1 1 .:,1 ccc B Ai B Ai = = = == = +=+ n i n i n i BABA 11 1 )(
  23. 23. . 1. 3. , . ..: 23 , 30, 1.1: for (i= to ) for (j=C to D) ... K ... ... K ... end for end for ( ) B D i A j C T n K = = =
  24. 24. . 2. (.) (.) , . , (.) 24 , 30, 1.1: 1. 2. . )()1()( 22 nnnnnn =+=+= )( 6 1 6 3 6 2 6 )12)(( 6 )12)(1( )( 323 2 nnnn nnnnnn n =++= ++ = ++ =
  25. 25. . 3. (.) . : 25 , 30, 1.1: 0 1 1a a a = = 1 0.52 B x x x= = ( ) ( ) ( ) n n m n n m nm m m a a a a a = = =1 1 1/ 1/k k a a a a a a = = = B BA A x x= ( ) / / ( / ) m m m n m n m n m n m m m a a a a a a a a a b a b + = = = =
  26. 26. . 1 : 26 , 30, 1.1: 2 1 2 0 2 ( ) (2 1) ( ) 2 (2 1) ( ) 5 ( 4 ) log n n n f n n n n f n f n n n = + + = + = + +0 2 3 22 4 6 5 0.01 6 7 62 44 8 ( ) 5 ( 4 ) log ( ) (2 ) ( ) log ! 1000 14 ( ) 1000 4( ) 2 ( ) 4 n n n n n n f n n n f n n f n n n n f n n f n f n n n n = + + = + = + + + + = + = = + +
  27. 27. . 2 : 27 , 30, 1.1: for i=1 to n for j=1 to n a=a+1 end for b=a+a*a end forend for
  28. 28. . 3 : 28 , 30, 1.1: for i=1 to n a=a/2 for j=1 to n a=a*10 end for b=a+a*a/2b=a+a*a/2 for j=i+1 to n a=a+9 end for end for
  29. 29. . 1 : 29 , 30, 1.1: procedure minArray(A) min=A[1] for i=2 to nfor i=2 to n if (A[i]
  30. 30. . 1 1. 1. 2. 2. 1. 30 , 30, 1.1: 1. 2.
  31. 31. . 2 (InsertionSort). : 31 , 30, 1.1: procedure InsertionSort(A) for i=2 to n for j=i-1 to 1 if (A[j]>A[j+1]) temp=A[j] A[j]=A[j+1] A[j+1]=temp else break end if end for end for end procedure
  32. 32. . 2 1. .. [5 4 3 1 2] . 2. ; 3. ; 4. 32 , 30, 1.1: 4. . 5. ; 6. ; 7. .