›—30 œ‘—œ‘ 1.1

download  ›—30 œ‘—œ‘ 1.1

of 32

  • date post

    16-Dec-2015
  • Category

    Documents

  • view

    85
  • download

    1

Embed Size (px)

description

ΠΛΗ30 ΜΑΘΗΜΑ 1.1

Transcript of  ›—30 œ‘—œ‘ 1.1

  • 30 1:

    1.1:

  • .

    .

    1.

    2.

    3.

    1.

    2 , 30, 1.1:

    2.

    3.

    4.

    .

    1.

    2. (.)

    3.

    .

  • .

    3 , 30, 1.1:

    , ,

    (-)

  • . 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 -

  • . 2.

    ,

    :

    : for, while, dowhile : ifelse ifelse

    5 , 30, 1.1:

    ( .. +,-,*,/,mod)

    ( )

  • . 3. 1.

    .

    .

    :

    6 , 30, 1.1:

    :

    SelectionSort :

    LinearSearch :

    (, ) .

    ( )T n n=

    2( ) 3T n n n= +

  • . 3. 1. ( LinearSearch) ( Linear

    Search)

    7 , 30, 1.1:

    procedure LinearSearch(A,x)

    for i=1 to nif (A[i]==x)

    A n , x. .

    return end if

    end for

    return end procedure

  • . 3. 1. ( LinearSearch)

    :

    ( ). , , :

    8 , 30, 1.1:

    ( ). , :

    . .

    1( ) 1

    n

    iT n n

    =

    = =

    ( ) 1T n =

  • . 3. 1. ( SelectionSort) ( SelectionSort)

    9 , 30, 1.1:

    procedure SelectionSort(A)

    for i=1 to npos=ifor j=i+1 to n

    if (A[j]

  • . 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 51 3 5 4 2

    1 2 3 4 51 2 5 4 3

    1 2 3 4 5 1:

    2:

    3:

    4:

    5:

    :

    1 2 3 4 51 2 3 4 5

    1 2 3 4 51 2 3 4 5

  • . 3. 1. (O SelectionSort) .

    ( if) ( ). :

    11 , 30, 1.1:

    1 1( ) [1 ( 2) 3]n n

    i j iT n = = += + + = 1 1

    1 1

    1

    1

    1

    1 1 1

    2 21

    2

    [4 2( 1)][4 2( ( 1) 1)][4 2( )][4 2 2 ]4 (2 ) (2 )

    ( 1)4 2 2 4 2 22

    3

    i j in n

    i j in

    in

    in

    in n n

    i i i

    n

    i

    n i

    n i

    n i

    n i

    n nn n i n n

    n n

    = = +

    = = +

    =

    =

    =

    = = =

    =

    = + =

    = + + + =

    = + =

    = + =

    = + =

    += + = + =

    = +

  • . 3. 1. (O SelectionSort) .

    ,

    if. :

    12 , 30, 1.1:

    ( ) [1 ( 1) 3]n nT n = + + = 1 11

    1

    1

    1 1 1

    2 21

    2

    ( ) [1 ( 1) 3][4 ( ( 1) 1)][4 ][4 ]4 ( ) ( )

    ( 1)4 42

    0.5 2.5

    n n

    i j in

    in

    in

    in n n

    i i i

    n

    i

    T n

    n i

    n i

    n i

    n i

    n nn n i n n

    n n

    = = +

    =

    =

    =

    = = =

    =

    = + + =

    = + + + =

    = + =

    = + =

    = + =

    += + = + =

    = +

  • . 3. 2.

    :

    LinearSearch .

    SelectionSort .

    13 , 30, 1.1:

    :

    .

    (.)

  • . 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 = +

    )()( 2nn =

    )()( 2nn =

  • . 3. 2.

    ; :

    :

    15 , 30, 1.1:

    < < < <

    :

    n. :

    :

    k >0 :

    k >0 :

    a >1 :

    )()( knn =

    )()( nan =

    )(log)( nn k=

    )!()( nn = )()( nnn = nnn ( ) (1)n =

  • . 3. 3.

    .

    .

    16 , 30, 1.1:

    ! n, n .

    (.) .

  • . 3. 3. ( Fibonacci) :

    Fibonacci :

    17 , 30, 1.1:

    =

    =

    = 2,11,1

    n

    n

    fn

    n- .

    >+

    2,21 nff nnn

    1 2 3 4 5 6 7 8 9 101 1 2 3 5 8 13 21 34 55 ...

  • . 3. 3. ( Fibonacci) n- Fibonacci :

    18 , 30, 1.1:

    procedure Fibonacci(n)

    A[1]=1A[2]=1for 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 forreturn A[n]

    end procedure

  • . 3. 3. ( Fibonacci) ;

    19 , 30, 1.1:

    procedure Fibonacci(n)

    if (n=1) return 1 else if (n=2) return 1else

    a=1

    : i,n,a,b,c

    T(n)=5 T(n)=(1)

    a=1b=1for (i=3 to n)

    c=a+ba=bb=c

    end forend ifreturn c

    end procedure

  • . 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)

  • . 1. 1.

    :

    21 , 30, 1.1:

    ....

    ++

    ....

  • . 1. 2. for for for for.

    ..:

    22 , 30, 1.1:

    ..:

    for (i=A to B)

    :

    for (i=A to B)... K ...

    end for

    =

    =

    B

    AiKnT )(

    =

    +=B

    Ai11

    =

    +=n

    inni

    12/)1(

    =

    ++=n

    innni

    1

    2 6/)12)(1(

    =

    +

    =

    n

    i

    ni

    x

    xx

    0

    1

    11

    .:,1 cccB

    Ai

    B

    Ai = =

    = == =

    +=+n

    i

    n

    i

    n

    iBABA

    11 1)(

  • . 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 CT n K

    = =

    =

  • . 2. (.) (.) ,

    .

    ,

    (.)

    24 , 30, 1.1:

    1.

    2.

    .

    )()1()( 22 nnnnnn =+=+=

    )(61

    63

    62

    6)12)((

    6)12)(1()( 323

    2

    nnnnnnnnnn

    n =++=++=++=

  • . 3. (.) .

    :

    25 , 30, 1.1:

    0

    1

    1aa a

    =

    =

    10.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

    =

    =

    =

    BBA Ax 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

    +

    =

    =

    =

    =

  • . 1

    :

    26 , 30, 1.1:

    21

    20 2

    ( ) (2 1)( ) 2 (2 1)( ) 5 ( 4 ) log

    n n

    n

    f n n n nf nf n n n

    = + +

    = +

    = + +0 23

    224

    65

    0.016

    7

    62 448

    ( ) 5 ( 4 ) log

    ( ) (2 )( ) log ! 1000 14( ) 1000

    4( ) 2( ) 4

    n

    n

    n

    n

    n

    n

    f n n n

    f n nf n n n nf n nf n

    f n n n n

    = + +

    = +

    = + + + +

    = +

    =

    = + +

  • . 2 :

    27 , 30, 1.1:

    for i=1 to nfor j=1 to n

    a=a+1end forb=a+a*a

    end forend for

  • . 3 :

    28 , 30, 1.1:

    for i=1 to na=a/2for j=1 to n

    a=a*10end forb=a+a*a/2b=a+a*a/2for j=i+1 to n

    a=a+9end for

    end for

  • . 1

    :

    29 , 30, 1.1:

    procedure minArray(A)

    min=A[1]for i=2 to nfor i=2 to n

    if (A[i]

  • . 11.

    1. 2.

    2. 1.

    30 , 30, 1.1:

    1. 2.

  • . 2

    (InsertionSort). :

    31 , 30, 1.1:

    procedure InsertionSort(A)

    for i=2 to nfor j=i-1 to 1

    if (A[j]>A[j+1]) temp=A[j]A[j]=A[j+1]A[j+1]=temp

    elsebreak

    end ifend for

    end for

    end procedure

  • . 21. .. [5 4 3 1 2]

    .

    2. ;3. ;4.

    32 , 30, 1.1:

    4. .

    5. ;6. ;7.

    .