Student book-ΑΕΠΠ

Click here to load reader

  • date post

    07-Apr-2016
  • Category

    Documents

  • view

    264
  • download

    4

Embed Size (px)

description

ΒΙΒΛΙΟ ΑΕΠΠ

Transcript of Student book-ΑΕΠΠ

  • -

    , -

    .

    , -

    .

    -

    . 14 , .

    ( 1-5) -

    ,

    . -

    -

    .

    . -

    -

    . -

    . -

    .

    ,

    .

    , , -

    . -

    .

    ( ). -

    , -

    . -

    , -

    , -

    . -

    , -

    .

  • iv

    , , -

    , -

    .

    :

    -

  • 1. ...........................................................................1

    1.1 .........................................................................3

    1.2 ..............................................................5

    1.3 ........................................................................8

    1.4 ..............................................................11

    1.5 ...........................................................16

    1.6 ..........................................................18

    2. ................................................................23

    2.1 ........................................................................25

    2.2 ..........................................................27

    2.3 ................................28

    2.4 / .............................28

    2.4.1 .............................................................30

    2.4.2 .................................................................32

    2.4.3 ..................................35

    2.4.4 .............................................37

    2.4.5 ..........................................................39

    3. ........................................................51

    3.1 .......................................................................................53

    3.2 + =........................54

    3.3 .........................................................................................56

    3.4 ...........................................................................................59

    3.5 .............................................................................................60

    3.6 ....................................................................................64

    3.7 ...................................................................................66

    3.8 ......................................................................................69

  • 3.8.1 .....................................69

    3.8.2 .....................70

    3.8.3 Fibonacci...................72

    3.9 .................................................................73

    3.9.1 .................................................................................73

    3.9.2 ................................................................................75

    3.9.3 ................................................................................75

    4. ...........................................................79

    4.1 ................................................................81

    4.2 ...................................................83

    4.3 .......................................................85

    4.4 ......................................................87

    4.5 .........................................................................90

    5. ............................................................................95

    5.1 ....................................................................97

    5.1.1 ..........................97

    5.1.2 ..................................98

    5.1.3 ........99

    5.1.4 .........................................100

    5.2 ...............................................................101

    5.3 .....................................................104

    5.3.1 ...................................107

    5.3.2 .....................................................108

    5.4 .........................................................................109

    6. .......................................................115

    6. 1 .....................................................117

    vi

  • 6.2 .....................................................................117

    6.2.1 ...........................................................118

    6.2.2 .....118

    6.2.3 ............................................119

    6.2.4 4 .........................................................127

    6.3 . ..................................................130

    6.4 ...........................................131

    6.4.1 ..............................132

    6.4.2 ......................................132

    6.4.3 .......................................132

    6.5 ....................................136

    6.6 .................................................137

    6.7 .............................................137

    7. ...................................................145

    7.1 ........................................................148

    7.2 ........................................................................148

    7.3 .....................................................................................149

    7.4 ................................................................................151

    7.5 ..................................................................152

    7.6 ................................................................................153

    7.7 ...............................................................153

    7.8 ......................................................................154

    7.9 - .............................................................155

    7.10 ................................................................157

    8. ......................................................................163

    8.1 ........................................................................165

    8.1.1 .........................................................................166

    vii

  • 8.1.2 .............................................................172

    8.2 ..................................................................173

    8.2.1 ...............................................173

    8.2.2 _ ...................................................175

    8.2.3 ....................................................178

    9. .................................................................................................183

    9.1. . ...........................................................185

    9.2. ..............................191

    9.3. .............................................................191

    9.4. .................................................198

    10. ..............................................................................203

    10.1. ................................................205

    10.2. ...............................207

    10.3. ..............208

    10.4. .............................................................................209

    10.5. ...................................................210

    10.5.1 ..................................213

    10.5.2 ....................................214

    10.5.3 ..........................216

    10.6. -. ...........................................220

    10.7. .................................................................................222

    11. ..................................229

    11.1. .................................231

    11.1.1 ....................................................................232

    11.1.2 ...........................................................................234

    11.1.3 ........................................................................235

    viii

  • 11.1.4 .........................................................................237

    11.2. .....................238

    11.2.1 ...................................................................239

    11.2.2 .............................................240

    11.3.

    ...............................................241

    11.4. ........248

    11.4.1 ............................................................249

    11.4.2 ..........................................................251

    11.5. .............................................252

    12. ..............................................................259

    12.1. ......................................................................261

    12.2. ..........................................................262

    12.3. ..........................................266

    12.4. ..................................270

    12.4.1 .......................................................................271

    12.4.2 ........................................................273

    12.5. .................................274

    13. .......................................................279

    13.1 ....................................................................281

    13.2 .........................................................................284

    13.3. ......................................................284

    13.4 ..............................288

    14. - .................................................................291

    14.1 .....................................293

    14.1.1 - .................................................293

    14.1.2 ..........................................................................297

    ix

  • 14.1.3 ......................................................................301

    14.1.4 .......................................................................305

    14.2 ...............................................308

    14.2.1 ........................................................310

    14.2.2 ...............................................310

    14.2.3 .............................................315

    14.3 ..........................................................315

    : ASCII....................................................................323

    ............................................................................326

    ................................................................................................327

    .............................................................................................333

    .................................................................................................337

    x

  • 1.

  • , . , , - , - , - . , - , - , .

    :

    -

    -

    -

    -;

    2000";

    -;

    , ;

    2

  • 1.1

    , . , , . - , - , , -, . - - , .

    : - , , , .

    , , , -. , - .

    - . , - .

    , .

    , - , .

    - Robin Wood Nottingham.

    , .

    3

  • , , , , Pasteur Fleming, - .

    - - .

    -

    4

    - 2000(millennium bug). - . , 15 1999 - 150499.

    , - , - . 21 010100, .

    2000 . - () . - - . , -, , , - - , 2000.

    , - -. 2000 . , , .

  • , , , - , .

    , , -.

    , , , , , - , - .

    - , , , , - -.

    - , - -.

    , , -, -, , -, .

    1.2

    - . - , .

    -

    5

  • - . . - , - , , -.

    , , , , - . - . - , . - .

    . - . , , .

    - . , , -. - . - .

    1

    , . - , .

    6

  • , - :

    . -

    . .

    , . - , . , . - , , - . . -. .

    . - . , , . - - - .

    : .

    : -.

    . , - ( ) - ( ).

    .

    - . - . - -.

    7

  • 1.3

    . - . , . - - .

    : - , - .

    - . - - , .

    2

    .

    8

    : .

    - .

    , - .

    - . , .

  • - . , :

    (1)

    (2)

    (3)

    - . .

    (1) , :

    (1.1)

    (1.2) , -

    (1.3)

    (2) , - :

    (2.1)

    (2.2)

    (2.3)

    (3) , :

    (3.1) -

    (3.2)

    (1.1) -:

    (1.1.1)

    (1.1.2)

    (1.1.3)

    9

  • (1.2), :

    (1.2.1)

    (1.2.2) -

    (1.2.3)

    , - -. . , - , - .

    - . - -. :

    -

    - ,

    - , . , - - .

    1.1.

    10

  • . - , .

    1.4

    - . - - .

    - . - . - . , -. -, - .

    11

    . 1.1.

  • . - . , , .. - -, - .

    3

    , -

    -

    . -

    , -

    -

    .

    : - .

    , - . :

    , , -, . - . . - .

    ; . , -;

    - . , . - .

    12

  • 1.1.

    : 9

    : : 2

    :

    /

    1 10

    2 17

    3 15

    . - 100 , - . . - 1.1.

    , . , - . - .

    : 100 ; , , . , , . .

    : - , ; . - 92 8. , , - .., 5809 , 5287 522 . -

    13

  • -. , , . - , - .

    - . , 10 13 .. , -. - , - 1.2.

    1.2. 1999-2000.

    %

    0 9 522 9,0

    10 13 1211 20,8

    14 15 2120 36,5

    16 17 1180 20,3

    18 20 776 13,4

    5809 100

    1.2 - , - ( ) - - ( ).

    -, . , 1.2, , - . - 1000 .

    14

  • , - .

    , - . , .

    , . . -, -, , - . , ( ), .

    15

    . 1.2. .

  • - ( 1.3):

    ,

    , -

    , , .

    1.5

    - , , . , . - .

    1. , :

    , . - , -, - .

    , , , . , .

    , , . - - . -, .

    16

    . 1.3. -

  • 2. , - :

    , - . -, - , .

    , , . - . -, , - .

    , - - . - . - , . - .

    3. , - . -, :

    , , . - .

    :

    , .

    , -

    17

    -

    ,

    -

    -

    ,

    .

  • , . .

    :

    .

    , . - - .

    :

    .

    1.6

    , . - - . -, , . - , .

    , , - , , ;

    -. . - .

    - . , . , , -

    18

  • - . - . -, , .

    . . - , , . , . - , , .

    - , . , - 3 .

    -

    ,

    ,

    ,

    .

    , :

    , , ,

    , - ,

    , - .

    , .

    19

  • .

    - . . . , , . - .

    - . - - . - , -. . . - , - .

    , , , - , , , .

    20

  • -

    .

    .

    .

    , , -.

    - 1.4.

    .

    -;

    -.

    1. Jacques Arsac, Les machines a penser Des ordinateurs et des hommes,Seuil, Paris, 1987.

    2. Emanuel Falkenauer, Genetic algorithms and grouping problems, Wiley,1998.

    3. Les Goldschlager & Andrew Lister: Computer Science A modernintroduction, Prentice Hall, 1990.

    4. R. Kadesch, Problem Solving-Across the Disciplines, Prentice HallEngineering, Science & Math, 1996.

    5. Nicholas Negroponte, Being digital, Alfred Knopf Inc, 1995.

    6. G. Polya, How to solve it A new aspect of mathematical method,Princeton University Press (second edition renewed), 1985.

    21

  • http://snow.utoronto.ca/Learn2/targets8.htm

    , . - , , , -. .

    http://www.awesomelibrary.org/Classroom/Science/Problem_Solving/Problem_Solving.html

    - . -, .

    http://www.suremath.com/suremath/suremath/essential.html

    - . - , .

    http://www2.hawaii.edu/suremath/click.html

    , , - , (, , ) - .

    http://www.infinn.com/creative.html

    - , - , - .

    22

  • 2.

  • - . , - . , , . , - - . , - , - . , - , , -, -. - , - . - , , .

    :

    ,

    ,

    - ,

    ,

    -.

    ;

    ;

    , ;

    3+6+9++999;

    24

  • 2.1

    , 1 n. . -, . - 25 , - -.

    , , . , - .

    : ,

    ,

    .

    .

    (input). , . - , -

    25

    (algorithm) Abu Jafar Mohammed ibn Musa al Khowarizmi, 825 .. Algoritmi dixit ... ( - ....). al Khowarizmi ( al-jabr=-), - . - , - . 20 .

  • - .

    (output). -.

    (definiteness). . , , - .

    (finiteness). - . - -, (computationalprocedure).

    (effectiveness). - . , .

    - . , , -:

    ,

    ,

    ,

    ,

    ,

    ,

    ,

    .

    . , , , , - , - . , , -

    26

  • , ( ) .

    2.2

    -. , , , .

    H , , :

    (hardware). - , ( , - .).

    (programming languages). (, - ) - . - ( assembly C) ( Basic Pascal). -, . , ( ).

    (theoretical). , - - . , - . -, .

    (analytical). (computerresources) , -

    27

  • , CPU / .. - 5.

    2.3

    :

    (free text), . - - , .

    (diagramming techniques), . , , (flow chart). , - .

    (natural language) . , - , -, .

    (coding), - .

    - , .

    2.4 /

    28

  • 29

    -, . , . - :

    , ,

    , ,

    , -,

    , . - .

    ..

    .

  • , - . , - , , , - -. ( ), .

    2.4.1

    ( ) , - . . - - . .

    1. A

    , -

    .

    _1

    a

    b

    c a + b c

    T _1

    . , . - . - , a , a .

    30

    = -

    = -

  • , , . - .

    a b - : c a + b. - . :

    - , , . - , - . , =

    31

    (constands). - - .

    , .. 123, +5, -1,25

    .. ,

    ,

    (variables). , . - , - . - , , - .

    (operators). - . -, .

    (expressions). - (operands), -. - . . .

    . 2.1.

    1

  • . - .

    , - . - . - , -.

    a b , c -, . , - (), (), - (). - , 2.1.

    2.4.2

    / . . , . - . , - . - , , , . , .

    - ( ) - . - . - , - .

    32

  • 2.

    .

    , -, , . , , , . -.

    _2

    a

    a < 0 a a*(-1) a

    _2

    .... :

    : ( ), - . , .

    ... , , - . , - _. .

    _1

    _2

    ...............

    _

    _

    , a . -, (-), (), (-). - 2.1.

    33

    + =5 5 =5 5

    .

  • 3.

    , -

    , -

    .

    _3

    a, b

    a < b

    c a + b

    c a * b_

    c

    _3

    34

    . 2.2. 2

  • -, :

    _

    2.4.3

    - - . , 1 24, . - .

    35

    . 2.3. 3

  • 4.

    , 1 2 3 -

    .

    _4

    a

    a = 1

    _ a = 2

    _ a = 3

    _

    _4

    , ... (select case), .

    36

    . 2.4. 4

  • 5.

    -

    .

    _5.

    ;

    age

    age 100

    _

    _5

    2.4.4

    . ... , ( ) .... , .

    6.

    -

    . , -

    80 , -

    . -

    1.70, .

    37

  • _6

    ,

    < 80

    < 1.70

    ,

    ,

    _

    < 1.70

    ,

    ,

    _

    _

    _5

    ,

    38

    . 2.5. 6

  • . - . - - . , , - , -. - . - . ( ) . - -.

    2.4.5

    , - -. -, - , . , . - -,

    = *

    . - - ( ). -

    39

  • - .

    7.

    : ...

    1

    100.

    . , - . - , - .. 5, 207, -32 . - - 1. - , i, 1 100 1.

    i i + 1

    i i 1. 100 i i + 1. - .... :

    _

    : , . , _-. :

    _7

    i 1 i 100

    i

    i i + 1_

    _7

    40

    i i + 1 i -

    ,

    _ -

    .

  • 8:

    .

    : , . , , - , - , . :

    1.

    2.

    3. 1.

    , ( ). , - . , - . , 3 :

    3. , 1, .

    . : , , - . - , .... - :

    _8

    x

    x > 0

    x

    x

    _

    _8

    , . ,

    41

    -

    ,

    .

  • . , - , ,.. 999999. - . ... :

    x 999999

    9. :

    _..._

    . , -

    .

    _9

    _

    x

    E x

    _ x < 0

    _9

    , - x . , - .

    10.

    : ......

    100 1

    100.

    - , - ....... .

    42

    _-

    ..._ -

  • _10

    Sum 0 i 1 100

    Sum Sum + i_

    E Sum

    _10

    , ...... , - i (=1) (=100). i 1, , 1. Sum , - 0, - . Sum - .

    43

    Sum Sum+i - Sum

    i

    . 2.6. 10

  • 11. :

    .........

    1 100.

    -. , - i.

    _11

    0 i 2 100 _ 2

    + i_

    E

    _11

    ....... , , . , . , - , :

    k 100 0 _ -1

    , -. . , - f(x) x 0 1,

    x 0 1 _ 0,01

    12.

    -, . -. , , - . , ,

    44

    k 5 5

    k 5 1

  • , , - .. -, 2.7.

    , - . , . - ( ), - , . , , .

    , , , 45 19. - - , . - 2.8 , . , , - . , .

    45

    45

    x 19

    405

    + 45

    855

    . 2.7.

    .

    45 19 45

    90 9 90

    180 4

    360 2

    720 1 720

    = 855

    . 2.8. -

    .

    (shift)

    - , 0 1, -, , .. 17 - 00010001 , byte. , 0 - 0, 00100010 , 34 . , , - , 1 0, 00001000 , 8 . - , - .

  • 46

    1.

    : , +, ,: ,: , .

    2.

    - , , _ (underscore). , .

    3.

    +, -, *, /, ^

    : , , : (), (), ().

    4.

    , , , .

    5.

    6.

    _

    1

    _1

    ............

    _

    _

    _

    _

    ......

    _

    _

  • 47

    7.

    _

    _

    _

    1 2 _

    _

    8.

    , , , ..

    9.

    , , - , ..

    10.

    - , !, !.

    11.

    12.

    ( ) // ... //. - // ... //.

  • , - . , , . - . , , - (shift), . - - -.

    - .

    : ( )

    :

    :

    M1 M2, M1, M2 1 P=M1*M2

    1

    2

    3

    4

    5

    6

    7

    P=0

    M2>0, 3, 7

    2 , P=P+M1

    1=1*2

    2=2/2 ( )

    2

    P.

    - .

    __

    // 1,2 //

    P 0 M2 > 0

    M2 mod 2 = 1 P P+M1M1 M1*2M2 [M2/2]

    _

    // P, 1,2 //

    __

    48

  • -. -. . , - . - , -, , .

    , , , , , -, , .

    -

    1. .

    2. ;

    3. -;

    4. ;

    5. -.

    6. / ;

    7. .

    8. - .

    9. .

    10. .

    11.

    49

  • .

    12. - .

    13. ; - ;

    1. ., ., ., , , 1991.

    2. , , - , 1993, .

    3. , Pascal, Art of Text, , 1998.

    4. .. , - , , 1990.

    5. D. Brunskill and J. Turner, Understanding Algorithms and Data Structures,McGraw-Hill, 1996.

    6. D. E. Knuth, The Art of Computer Programming: Fundamental Algorithms,Vol.1, 3rd edition, Addison Wesley, 1997.

    7. M.A. Weiss, Data Structures and Algorithm Analysis, 2nd edition,Benjamin/Cummings, 1995

    http://hissa.ncsl.nist.gov/~black/CRCDict/

    , - (Algorithms, Data Structures, and Problems Terms and Definitionsfor the CRC Dictionary of Computer Science, Engineering and Technology)

    http://www.ee.uwa.edu.au/~plsd210/ds/ds_ToC.html

    , - .

    50

  • 3.

  • , - . - . , -, . - , , - , .

    :

    ,

    -,

    - ,

    -,

    -,

    .

    FIFO;

    -, ;

    - ;

    , -;

    52

  • 3.1

    (data) - . , . , , , , ., , . , , , . (information). - , -. . -, , , . , , , (Information Theory), .

    - , . , - :

    . (hardware), , - (representations). , SCII (.), EBCDIC, 1 2 ..

    . (high level programming languages) - (types) (variables) . - , , .

    . (data structure) ., (record), , . (fields) (attributes) - , , . -

    53

    (byte)

    11110001.

    H :

    _ -

    ASCII 437

    -

    928

    1 -

    EBCDIC

    241

    ( -

    )

    -14

    ( -

    -

    1)

    -15

    ( -

    -

    2)

    2 4

    bytes, -

    .

    -

    , -

    ,

    -

    , -

    ,

    ,

    .

  • . - .

    . . (Data-bases), (Data Modelling) - (Knowledge Representation) .

    3.2 + =

    , . , - . (data structure) -.

    : .

    (nodes). ( ) - :

    (access), .

    (insertion), - .

    (deletion), , - .

    (searching), , - .

    (sorting), .

    54

  • (copying), .

    (merging), - .

    (separation), .

    - . , , , . , - .

    - . , - . , . 1976 Wirth( Pascal)

    + =

    .

    .

    .

    : (1,1), (2,2), ...,(n,n), i i - i- , i=1,2,...,n.

    : - k k. , .

    55

  • .

    : -, -. (,n1),(B,n2), ..., (,n24). K - ni ( i=1, 2, ..., 24) - .

    : .

    : (static) (dynamic). - (dynamic memory allocation). - , , - . - . , -

    3.3

    - , . .

    , -. - ( , .). - . -, - (indexes) .

    , -

    56

  • , -. , - (square) n x n. , - . - , .

    1.

    table 100 . -

    _

    // table //

    Min table[1] i 2 100

    table[i] < Min Min table[i]_

    //Min//

    _

    Min. -, Min , -. Min - table.

    2.

    table m n . -

    , .

    . - , - . - .

    57

    . 3.1

    (-

    , , -

    )

  • _

    // m, n, table //

    sum 0 i 1 m

    row[i] 0_

    j 1 n

    col[j] 0_

    i 1 m

    j 1 n

    sum sum + table[i,j]row[i] row[i] + table[i,j]col[j] col[j] + table[i,j]

    _

    _

    // row, col, sum //

    _

    - , , - . , , . -, i 1 j - 1,2,,n. , i 2, j 1,2,,n. - i m.

    5x5. - , row , col - . sum- - .

    58

  • tablerow

    4 16 5 21 7 53

    28 9 38 13 51 139

    17 67 22 40 30 176

    20 40 10 3 13 86

    21 34 48 29 26 158

    col 90 166 123 106 127 612 Sum

    - , (stack) (queue), - , - .

    3.4

    . -, (top) , -. , , . - , LIFO

    59

    . 3.2. .

  • (Last-In-First-Out). - , .

    :

    (push) ,

    (pop) .

    , , (overflow) -. , , - , (under-flow) .

    - , 3.3. - ( top) . () top . - () top top .

    3.5

    . , - , , , .. - . , , (Operations Research), - (Queueing Theory), -. , - ( - ). - , - FIFO (First-In-First-Out).

    :

    60

    . 3.3 -

  • (enqueue) ,

    (dequeue) .

    , , : (front) (rear) , .

    3.4 (), - () .

    -, 3.5. rear - . , front, , . , -, - .

    61

    . 3.5

    . 3.4. .

  • 62

    FIFO LIFO

    LIF, FIFO. . . - -, , - . - , , .. - , - . .

    - - . , , ;

    o . , - . (.. ), . - FIFO .

    - , -. - .

    /

    1/1/99 4 100 400

    15/1/99 6 120 720

    10 1120

  • 63

    /

    30/1/99 5 200 1000

    .

    /-

    -

    -

    -

    -

    -

    -

    1/1/99 4 4 400 400

    15/1/99 6 10 720 1120

    30/1/99 5 5

    - . - , .

    ) LIFO

    30/1/99 5 6 , 120 . =5x120 = 600 . =1120-600=520. - 1000-600=400.

    ) FIFO

    30/1/99 5 , 4 - 1/1/99 1 15/1/99. =4x100+1x120=520 =1120-520=600. , 1000-520=480.

    )

    -, - . 1120/10=112. =5x112=560 =1120-560=560. 1000-560=440 .

  • 3.6

    (searching) . , . -, . .

    (sequential) (linear) . Sequential Search key - table. position - 0, , - , (-, 1 n).

    Sequential_Search

    // n, table, key //

    done position 0i 1 (done=) (i

  • , . , - 56 4 . , - () 11 9 -, . - . 11 - 12.

    , - . , - :

    ,

    ( , n 20), ,

    65

    . 3.6.

  • -, .

    3.7

    (sorting) (ordering). (ascendingsequence) . . , , , , - - . .

    . a1,a2,...,an (permutation) , - ak1,ak2,...,akn , (ordering function), f, :

    f(ak1) f(ak2) ... f(akn)

    A , - (descending sequence) .

    H (straight exchange sort) , . - -. - - (bubbles) , -

    66

  • . - (bubblesort).

    . - : 52, 12, 71, 56, 5, 10, 19, 90 45. . , -

    67

    / , - . - , - . (files). - , -, . , , , , -. (records), (fields), , - . , : , , -, , . (primary key) . - - (secondary keys), . (searching) - , - ( , , -, ..), ( -, , , , ..), (, .).

  • . (i).

    .

    // table, n //

    i 2 n

    j n i _ 1

    table[j-1] > table[j]

    table[j-1], table[j]

    _

    _

    _

    // table //

    table n - . - , - , , .

    table[j-1], table[j] . - .

    68

    . 3.7. .

    -

    .

    -

    -

    . -

    (quicksort).

    -

    -

    .

  • temp table[j-1]table[j-1] table[j]table[j] temp

    3.8

    (recursion), - . . , , - .

    3.8.1

    H . -, n, n , n!, :

    n! = 1 x 2 x 3 x x (n-1) x n

    ( )n

    n n n

    n!

    !=

    >

    =

    1 0

    1 0

    - . . - n .

    // n //

    n = 0

    product 1

    product n * (n-1)_

    // product //

    69

  • , n! , - 2.

    2

    // n //

    product 1 i 2 n

    product product * i_

    // product //

    2

    , - n , - . , - .

    3.8.2

    E () . . . x y. ( ), - -. , z, z , x y, z.

    __

    // x,y //

    x < y

    z x

    z y_

    (x mod z 0) (y mod z 0) z z-1

    _

    // z //

    __

    70

  • , , .

    // x,y //

    z y z 0

    z x mod yx yy z

    _

    // x //

    . , - 150 35. - z, x y, - . , - x y 150 35 ( ). 0 z, - x, 5.

    z x y

    35 150 35

    10 35 10

    5 10 5

    0 5 0

    - , . H .

    // x,y //

    y = 0

    z x

    z (y, x mod y)_

    // z //

    71

  • 3.8.3 Fibonacci

    - , , Fibonacci , - :

    F

    i

    i

    F F F ii

    i i i

    =

    =

    =

    = + >

    0 0

    1 1

    11 2

    Fibonacci :

    0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 .

    A -. Fibonacci Fn . - n.

    Fibonacci1

    // n //

    n 1 Fib nf0 0f1 1 i 2 n

    fib f0+f1f0 f1f1 fib

    _

    // Fib //

    Fibonacci1

    Fibonacci2

    // n //

    n 1 Fib n

    Fib Fib(n-1) + Fib(n-2)_

    // Fib //

    Fibonacci2

    72

  • - . - , . - . - . - . , , .

    Fibonacci , , . , - . - F5. - Fibonacci .

    3.9

    -. - , - . , .

    3.9.1

    . (pointer) - . - , .., - - , - . - , 3.8. -

    73

    . 3.8 -

  • .

    3.9 , , -.

    . 3.10 - .

    , - () - ( - ). , .

    , 3.11. () -, .

    74

    . 3.9.

    index pointer -

    . -

    ,

    -

    .

    . 3.10.

    . 3.11.

    , -

    (dynamic),

    ,

    -

    -

    .

    ,

    , -

    -

    -

    .

  • 3.9.2

    (trees) - , - . , - ( ). , , -. , , - . 3.12. . . , ... - , .

    3.9.3

    (graph) ( ) ( ) - . -, .

    75

    . 3.13.

    . 3.12.

  • - . - - . - , , , - .

    , -, . - . ( ), , . - , . - . . / - . - . , , .

    , , , ,, , , FIFO LIFO, , , -, , , .

    76

  • -

    1. ; .

    2. ;

    3. .

    4. ;

    5. - ;

    6. .

    7. .

    8. .

    9. ;

    10. .

    11. ;

    12. - .

    13. - .

    14. .

    15. - .

    16. .

    17. -.

    1. , , , 1996.

    2. , . , , 1993.

    77

  • 3. , Pascal, Art of Text, , 1998.

    4. , , , 1993.

    5. D. Brunskill and J. Turner: Understanding Algorithms and DataStructures, McGraw-Hill, 1996.

    6. D. E. Knuth: The Art of Computer Programming : FundamentalAlgorithms, Vol.1, 3rd edition, Addison Wesley, 1997.

    7. M.A. Weiss: Data Structures and Algorithm Analysis, 2nd edition,Benjamin/Cummings, 1995.

    http://hissa.ncsl.nist.gov/~black/CRCDict/

    , - (Algorithms, Data Structures, and Problems Terms and Definitionsfor the CRC Dictionary of Computer Science, Engineering and Technology).

    http://www.ee.uwa.edu.au/~plsd210/ds/ds_ToC.html

    , - .

    78

  • 4.

  • , - , . , , -. , -. .

    :

    ,

    ,

    ,

    ,

    .

    ;

    - ;

    ;

    80

  • 4.1

    , - . - . , , . , - . - .

    - :

    , , :

    , .

    , - :

    1. ,2.

    ,3. ( -

    ),4. (.. ),

    5. -

    (.. )

    . -

    , , -

    , -

    , -

    . -

    ,

    .

    81

  • 4 4, 6 . , - . , 1, , - 2, 3 4. - .

    ) :

    1. ,

    2. ,

    3. .

    :

    36 .

    82

    . 4.1. .

  • ) :

    1. ,

    2. - - .

    :

    30 .

    , -, , . , -. , - . , - - :

    - ,

    ( -),

    - , - .

    4.2

    - , - , . , -

    83

  • . , - - .

    . , . - ( ). -, :

    ,

    .

    .

    , - - . . - , :

    .

    -, - . - ., .

    84

    .

  • 4.3

    (divide and conquer) , - . , - . - , . (top-down).

    , :

    1. .

    2. - .

    3. -.

    4. -, -.

    : .

    , - n . . n - : names[1..n] phones[1..n] . , , ( ).

    , 3 -:

    1. names,

    85

    . 4.2. -

  • 2. names,

    3. names.

    . - - (, names). - , - .

    _

    // names, phones, onoma, arxi, telos //

    meso [arhi + telos]/2 onoma = names[meso]

    Tel phones[meso]

    onoma < names[meso]

    _(names, phones, onoma, arhi, meso-1)

    _(names, phones, onoma, meso+1,telos)

    _

    _

    // Tel //

    _

    . - - . .

    86

    . 4.3 -

    .

    -

    -

    .

  • , , -. - . , , . , - , - - . , - .

    . ( Bolzano) f(x)=0 - [a, b]. , , f(a).f(b)

  • . , - (bottom -up). , - . , - , -. .. -.

    , - . - , - . - :

    1. ,

    2. -,

    3. .

    - .

    - . , , .

    , , - , ab. - 1, - .

    88

  • 1

    // a, b //

    power 1 i 1 b

    power power * a_

    // power //

    1

    1 , , b b- . - , - a16 : (((2) 2)2)2. , - b. - power . , - 2 (, a=2), 0 1, 1 2, 2 4, 3 16 , .

    0 1 2 3 4

    20=1 21=2 22=4 24=16 28=256

    2

    0- 1 2 4 8

    . 4.5 2.

    , , - . , 27 , - 4 2, 27= 24 *22 *21. ab , -.

    89

  • 2

    // a, b //

    !:

    power[1] ai 1pow 1 pow < b

    i i+1pow 2* powpower[i] power[i-1] * power[i-1]

    _

    !:

    used 0result 1 used < b

    used + pow

  • - ( - ).

    , , .

    1,2, 5, 10, 20, 50 100 200, 500, 1000,5000 10000 . , , - . - 789 . 1 , 1 -, 1 , 1 , 1 , 1 2 , - 8 .

    , - . T , .

    // C, n, poso //

    find posocoins 0choice n (choice>0) (find > 0)

    C[choice]

  • C n - . - ( coins). , - .

    -. - . - : - , - . - - . - . - - -. , , - .

    , , , , .

    -

    1. - ;

    2. ;

    3. -;

    92

  • 4. - .

    5. .

    6. .

    7. , - .

    8. .

    1. : , , -, 1993.

    2. : . , , 1993.

    3. : , - , , 1988.

    4. : Pascal, Art of Text, , 1998.

    5. , , - , , 1996.

    6. , , , 1995.

    7. Niklaus Wirth: , , ,1990.

    8. G. Brassard and P.Bratley: Fundamentals of Algorithms, Prentice Hall,1996.

    9. T. Cormen, C. Leiserson and R. Rivest: Introduction to Algorithms MITPress, 1990.

    10. E. Horowitz, S. Sahni and S. Rajasekaran: Computer Algorithms,Computer Science Press, 1998.

    93

  • 11. I. Oliver: Programming Classics: Implementing the Worlds BestAlgorithms, Prentice Hall, 1993.

    http://www.cs.pitt.edu/~kirk/algorithmcourses/index.html

    -. .

    http://www.wisdom.weizmann.ac.il/~naor/puzzler.html

    puzzle. /.

    http://www.cs.sunysb.edu/~algorith/

    (Stony Brook) - . .

    94

  • 5.

  • - - . , - (, ). -, , () -. , - , , .

    :

    ,

    ,

    -,

    ,

    ,

    .

    ;

    ;

    96

  • 5.1

    - , . (performance) (efficiency) .

    - . - :

    1. ;

    2. ;

    3. , ;

    - . - .

    5.1.1

    - , -. - . -. - . , :

    ,

    ,

    .

    , - , - .

    97

  • : :

    1

    n 10A_

    m

    n n - 1M_ (m=0) (n=0)

    m

    1

    10 ( n=0).

    5.1.2

    (size) . - . , . , , n, .

    5.1 , :

    . 5.1.

    (n)

    98

  • 5.1.3 -

    :

    2

    x 123y 234 i 0 4

    i

    z x * y_

    x

    y

    z

    2

    . - 5 , :

    x y 2

    i

    i

    i

    i

    z (25)

    1

    6

    5

    5

    10

    x, y, z 3

    32

    - n , n. 5.2 n, - - :

    99

  • . 5.2.

    n

    5 42 -

    10 77 -

    100 707 -

    1.000.000 7 ()

    5.1.4

    - , - . , , , . - , - , . - , - . , :

    ,

    ,

    ,

    -,

    , .

    , , :

    -,

    -,

    ,

    100

  • .

    5.2

    , - . - . . - . , , . - , - .

    - . - , , , .. . . , ; , - . - :

    : -

    10 -

    .

    - :

    101

  • 3

    // a //

    low a[1]i 2 i < 10

    a[i] < low low a[i]i i+1

    _

    // low //

    3

    , - . - 10 , - . 3 - :

    11 3 2 56 32 69 81 90 222 2

    2 444 1 65 51 51 99 98 1 1

    90 11 333 38 224 61 73 80 7 59

    , . - :

    6 8 3 4 3 7 8 9 5 2

    3, - 2. , -, . , .

    , , - , - . (i < 10), .

    102

  • , . , - , - , .

    - , , - . 1/10, 10 . - 0,9. , - 0,9*0,9=0,81. - :

    -

    1 0,1 0,9

    2 0,19 0,81

    3 0,271 0,729

    4 0,344 0,656

    5 0,410 0,590

    6 0,469 0,531

    7 0,522 0,478

    , - 7 - 0,5 . - . , . - .

    :

    103

  • - ,

    , -. .

    a b . - , - . , -: a b b a, ., a0 b0 . , : a=b0 b=a0. . , - , . :

    t a, a b b t

    , , .

    5.3

    (empirical) (a posteriori)., -, (proces-sing time) (memory space). - .

    .

    , - .

    104

  • .

    - (theoretical) (a priori). n, (size) , - , . - , . , k n=k. - f(n) - (time complexity) (space complexity). - , . O (-notation), order - . .

    : f(n), O(g(n)), c n0, n n0 :

    ( ) ( )f n c g n.

    f(n)=2n3+5n2-4n+3. - , x ( ) - , . , 2 - g(n)=n3. , (n3). , . f(n)=5.2n+4n2-4logn, g(n)=2n, - f(n) 5 2n. , f(n), 1, 2, 3 - n . ( , n=10), 2n.

    -

    105

  • , , . , - , .

    , :

    (1). K . - .

    (logn). . - log , ln . , - .

    O(n). . - n .

    O(n logn). (n logn), ( -). .

    O(n2). . .

    O(n3). . - .

    O(2n). -.

    5.3 - - (n). - . - (n3) , - (23) . - , .

    106

  • . 5.3.

    n=20 n=40 n=60

    (n) 0.00002 0.00004 0.00006

    (n2) 0.0004 0.0016 0.0036

    (n3) 0.008 0.064 216

    (2n) 1.0 o 2.7 366

    (n!) 771 3 1032 3 1066

    . , , . 3, - .

    5.3.1

    C, (keycomparisons), . (moves) -. C M n , .

    , , . :

    C = 1 + 2 + + (n-1)

    C =( )n n 12

    , (n2).

    107

  • 5.3.2

    3.6 , . , (successful). , - (unsuccessful). . , .

    , - n -. , - , , - . , n-, n . , :

    ( ) ( )

    n

    n

    n n

    n

    n=

    + + +=

    +=

    +1 2 1

    2

    1

    2

    , - (n), .

    (n). , , . , - , .

    . 5.4.

    - (1)

    - (1)

    Fibonacci (n)

    O(n2)

    O(n)

    O(logn)

    108

  • 5.4

    , - , , - . , , . , - -. .

    , - / -. , , , - , ( ). - , - . - , , - , . - (parallel) , , -, - . , - .

    , 2 , , . - . , - .

    109

  • , .

    , . -, - , , , , ..

    , - , (Computa-tional Complexity), . - , -. (optimal), , -.

    (polynomial) . , (n), O(n3/2), O(n2) .. O(2n), O(n2 2n) O(nn), - .

    -, - . , :

    x1, x2, , xn ( n ). n/2 , - ,

    x1, x2, , xn ( n ). n/2 , - .

    , - . , - n , . (n2), - . , -

    110

  • . , - . . - (2n).

    ( ) -, - . (intra-ctable). -, . . . , - , . - , - .

    , -, NP-- NondeterministicPolynomial. - .

    - , (approximate) , . , , - .

    , , - , , . . -

    111

  • , .

    , .

    - , .

    -. - () - .

    - .

    , - (-, , ).

    / , -, , , -, , , , , ,

    -

    1. - ;

    2. -;

    3. .

    112

  • 4. ;

    5. - ;

    6. .

    7. - ;

    8. .

    9. .

    10. -, .

    11. ;

    12. ;

    13. ;

    1. , , , ,1993.

    2. , . , , 1993.

    3. , , - , , 1988.

    4. , Pascal, Art of Text, , 1998.

    5. . , , , , 1993.

    6. Niklaus Wirth, , , ,1990.

    7. G. Brassard and P.Bratley, Fundamentals of Algorithms, Prentice Hall,1996.

    8. T. Cormen, C. Leiserson and R. Rivest, Introduction to Algorithms MITPress, 1990.

    113

  • 9. E. Horowitz, S. Sahni and S. Rajasekaran, Computer Algorithms,Computer Science Press, 1998.

    10. I. Oliver, Programming Classics: Implementing the Worlds BestAlgorithms, Prentice Hall, 1993.

    http://www.csd.auth.gr/~contest/

    - . - .

    http://olympiads.win.tue.nl/ioi/

    -.

    http://acm.baylor.edu/acmicpc/

    Association forComputing Machinery (ACM).

    114

  • 6.

  • . - - , -. - . - , , -. - , . .

    :

    .

    - .

    .

    .

    -

    ;

    ;

    ;

    ;

    - ;

    116

  • 6. 1

    , - , .

    .

    .

    -.

    , - , . , , , - -. .

    , - .

    . , , , , . , . - , , -.

    6.2

    - . , - - .

    (hardware) , - , -

    117

    -

    -

    -

    ()

    ()

  • 1945 , . , , - .

    6.2.1

    , 0 1, - . , .

    ENIAC , , - , . , . , - , .

    - 0 1, , , .

    6.2.2

    - , , - 0 1. ADD () - , - . - -. , (assembler).

    , , -

    118

    , -

    -

    .

  • . . - , . - , . - , .

    6.2.3

    - -, 50 .

    1957 IBM FORTRAN. FORTRAN FORmulaTRANslation, . FORTRAN - . FORTRAN - , - , . FORTRAN , . - FORTRAN , - .

    119

    -

    . -

    -

    -

    . 6.1. ,

    1 10

    10101000 0000101010001100 000000010011110001010001 0000000101000011 0000000111000000 1111101010001100 0000001011111111

    sum = 0

    FOR index=1 TO 10

    sum=sum+index

    NEXT index

    END

    INDEX=$01

    SUM=$02

    LDA #10

    STA INDEX

    CLA

    LOOP ADD INDEX

    DEC INDEX

    BNE LOOP

    STA SUM

    BRK

  • FORTRAN - , , . .

    1960 , - COBOL. COBOL (Cm-mon Business Oriented Language - -) , - , FORTRAN . COBOL - . - .

    , ALGOL (ALGOrithmic Language - ). ,

    120

    C PROGRAM EQUATION

    READ(*,1) A,B

    1 FORMAT(F5.1)

    IF (A.EQ.0) GO TO 20

    X=(-1.)*B/A

    WRITE(*,2) X

    2 FORMAT(X=,F10.2)

    GO TO 50

    20 IF (B.EQ.0) WRITE(*,3)

    IF (B.NE.0) WRITE(*,4)

    3 FORMAT()

    4 FORMAT()

    50 STOP

    END

    .6.2. FORTRAN -

    . , -

    .

    4, 77, 90/95 Visual

    FORTRAN. .

  • 121

    IDENTIFICATION DIVISION.

    PROGRAM-ID. EQUATION.

    ENVIRONMENT DIVISION.

    CONFIGURATION SECTION.

    SOURCE-COMPUTER. IBM-PC.

    OBJECT-COMPUTER. IBM-PC.

    SPECIAL-NAMES. DECIMAL-POINT IS COMMA.

    DATA DIVISION.

    WORKING-STORAGE SECTION.

    77 X PIC S9(6)V9.

    77 A PIC S9(6).

    77 B PIC S9(6).

    77 W-X PIC -(6),-.

    PROCEDURE DIVISION.

    ARXH.

    DISPLAY .

    ACCEPT A.

    DISPLAY .

    ACCEPT B.

    DISPLAY .

    IF A = 0 GO TO ROYT-1.

    COMPUTE X = B * (- 1) / A.

    MOVE X TO W-X.

    DISPLAY H : W-X.

    STOP RUN.

    ROYT-1.

    IF B = 0

    DISPLAY

    ELSE

    DISPLAY .

    STOP RUN.

    . 6.3. COBOL Grace Marray Hopper

    1960. COBOL

    -

    . COBOL

    (divisions).

    , ADD, MULTIPLY, MOVE

    .. . -

    .

    .

  • 1960, .

    60 PL/1(Programming Language/1 1) , -, , FORTRAN COBOL .

    - . 60 LISP (LISt Processor- ), - PROLOG(PROgramming LOGic ) 70. - ( , , ..).

    , 60 , - BASIC PASCAL.

    122

    10 REM

    20 INPUT A=,A

    30 INPUT B=,B

    40 IF A=0 THEN 100

    50 X=-B/A

    60 PRINT X=;X

    70 END

    100 IF B=0 THEN PRINT ELSE PRINT

    110 END

    . 6.4. BASIC 1964 Dartmouth College -

    Kemeny Kurtz.

    . BASIC -

    (1975).

    8 ROM Bill Gates Paul Allen. , -

    Microsoft Bill Gates

    . GWBASIC 1981 IBM PC. -

    ,

    .

    QuickBASIC Visual BASIC. -

    .

  • BASIC (Beginners All Purpose SymbolicInstruction Code -) , , . , (interpreter). , . Microsoft QuickBasic Visual Basic, -

    PASCAL ( NiklausWirth) - . 1970 - ALGOL. , - . - . PASCAL - ADA Modula-2.

    1960 - . -

    123

    TO KYBOS :A

    REPEAT 4 [FD :A RT 90]

    PU SETPOS [20 20] PD

    REPEAT 4 [FD :A RT 90]

    PU HOME PD

    REPEAT 2 [FD :A RT 45 FD 29 RT 135]

    PU SETX :A SETY 0 PD

    REPEAT 2 [FD :A RT 45 FD 29 RT 135]

    HOME

    END

    . 6.5. LOGO 1967

    Seymoyr Papert. . -

    -

    . -

    .

  • . .

    C. C BELL Unix, -, Pascal - - . C C++, -. - 70 - . - .

    , - (Internet), JAVA. H JAVA SUN , , . -, .

    -

    124

    (DEFUN a-exisosi (a b)

    (setf apot (- (/ b a)))

    (princ )

    (princ a)

    (princ x + )

    (princ b)

    (princ = 0 = )

    (princ apot))

    . 6.6. LISP 1959 . -

    .

    , , -

    . , -

    . ..

    (a-exisosi 2 5).

  • -. - , - , - .

    - (object driven programming) (visualprogramming).

    125

    #include

    int main(int argc, char* argv[])

    {

    float a, b;

    printf(A = );

    scanf(%f, &a);

    printf(B = );

    scanf(%f, &b);

    if (a == 0) {

    if (b == 0) {

    printf(\n);

    }

    else {

    printf(\n);

    }

    }

    else {

    printf(X = %f\n, -b/a);

    }

    return 0;

    }

    . 6.7. C Bell -

    & 1972 Dennis Ritchie. C

    -

    .

    UNIX, C -

    .

    .

  • - . - - , - .

    - Visual Basic, Visual C++ Java.

    126

    -

    , -

    -

    CLEAR

    ? 1.

    ? 2.

    ? 3.

    ? 4.

    INPUT [1..4] : TO CHOICE

    DO CASE

    CASE CHOICE=1

    APPEND

    CASE CHOICE=2

    LABEL FORM PELATES

    CASE CHOICE=3

    BROWSE

    OTHERWISE

    QUIT

    END CASE

    . 6.8. dBASE 70

    Ashton-Tate 8-bit -

    . dBASE

    -

    () . dBASE -

    ,

    -

    . -

    . dBASE III Plus.

    Clipper , -

    . , -

    xBASE,

    Access. -

    .

  • 6.2.4 4

    ( 3 ) - . - . , - . - - . - - 4 .

    , , -

    127

    - :

    -. .

    . - . -.

    -.

    - .

    , - .

  • 128

    - - . (procedural) . - , - . - :

    (object -oriented languages)

    (functional languages) .. LISP

    (non procedural languages) ..PROLOG. -.

    (query languages) .. SQL.

    -. :

    . -. - . - : (science-oriented langua-

    ges) .. FORTRAN (business-oriented languages)

    .. COBOL. .. BASIC, Pascal.

    (system programminglanguages) .. C.

    (artificial intelligence languages) ..LISP, PROLOG.

    . - .. -, , -, , - ..

  • - , .

    SELECT ENAME, JOB, SAL

    FROM EMPLOYES

    WHERE DEPTNO=20

    AND SAL > 300000;

    SQL EMPLOYES , 20 300.000 .

    129

    . - - . - . . - . -.

    -

    ,

    .

    , , - . - , - - .

  • 6.3

    , - . -, - . , - , -, .

    , , .

    - .

    : - 48 (- -), 10 (0-9) . (A-Z a-z) .

    , . - , - , .

    (accidence) (syntax).

    - . - , , , .

    130

  • .

    - - .

    (Semantics) .

    , - -.

    .

    - . , , - , .

    , - .

    - , . - ( GW-Basic QuickBasic) ( Basic Visual Basic).

    6.4

    - , ,

    131

    , -

    ,

    .

  • .

    6.4.1

    - (top-downprogram design) - , , , - , -.

    - , .

    - , 6.4.

    6.4.2

    . -, (mo-dule), -.

    - -.

    - , , - .

    6.4.3

    ,

    132

    -

    -

  • (structured programming). - 1960.

    1964 Bohm Jacopini -. , 1968 Edsger Dijkstra - - . GO TO Statement Considered Harmful - - GOTO -. , .

    , . , GOTO .

    133

    . 6.4.

  • 134

    GOTO:

    - GOTO (). GOTO , . . GOTO, - , - . GOTO.

    -, - ,

    ,,,,,

    >0 GOTO 1

    =0 GOTO 2

    GOTO 4

    1:

    GOTO 4

    2:

    GOTO 4

    4:! ,

    ,,,,

    >0

    _ =0

    _

    ,,,

    GOTO - .

  • GOTO .

    -, , , - .

    , , -

    .

    -

    .

    .

    2 - .

    - GOTO, - .

    , - .

    135

    , - GOTO . -, .

    GOTO - -.

  • 6.5

    - 70 . - (object-oriented) . .

    - . - () . , . .

    , (objects). - ,

    136

    .

    .

    .

    .

    .

    .

    .

  • -. , , - ;, ;, ; ;. - - 11.

    - , .

    6.6

    , -. - . - . - , . , - .

    5, - , .

    6.7

    -, , .

    . -

    137

    -

    -

    OCCAM.

  • , (compilers) (interpreters). - - . - . -.

    (source), - - (object).

    -, . - , (libraries) . - (linker-loader). (executable), - . - .

    -, . - . - , . , -.

    138

    . 6.5.

  • - . , , - , - , - .

    - . . , - .

    , - , - . - . - , - , . -

    139

    . 6.6.

  • , - -.

    - (editor). -, -

    , : , - . - .

    - . (visual) - ( -, , ) - .

    - . - , - -. , , - .

    - , , - , - . - , .

    . - , -

    140

    -

    -

    . -

    -

    -

    ,

    -

    .

  • , . , , - .

    -

    ;

    ;

    ;

    ;

    -;

    ;

    -;

    ;

    ;

    ;

    ;

    -;

    ;

    -;

    , , , -, , , - , , ,

    141

  • 1. Ph. Breton, , , ,

    2. . , , , 1986.

    3. . -, , , , , 1992.

    4. , - , , 1986.

    5. .-., FORTRAN 77 FORTRAN90, , , 1995.

    6. . -. , COBOL , , , , 1992.

    7. . -. , Structure & Advanced COBOL, -, , 1992.

    8. . -. , GWBASIC , , , 1992.

    9. . -. -. , PRO LOG, , , 1991.

    10. . , LOGO , -, , 1991.

    11. . , C , , -, 1995.

    12. M., SQL 4 , , , 1995.

    13. E. Horowitz, , -, , 1995.

    14. R. Shackelford, Introduction to Computing and Algorithms,Addison-Wesley, USA, 1998.

    15. W. Hutching-H. Somers, An Introduction to Machine Translation,Academic Press, London, 1992.

    142

  • cuiwww.unige.ch/langlist

    . - 2000 .

    www.swcp.com/~dodrill/

    - .

    www.progsource.com

    , , - - Pascal, Delphi, C/C++, Java, Perl, Visual Basic.

    www.hensa.ac.uk/parallel/

    .

    Softwaredesign.com/objects.html

    - .

    Iamwww.unibe.ch/~scg/Ooinfo

    , .

    143

  • 7.

  • , , - . - .

    . , , .

    , - , .

    :

    .

    .

    .

    .

    , , - .

    -;

    ;

    ;

    - ;

    146

  • - , . , - . - .

    :

    , - . -, - .

    . - , . - - , - .

    -, , - .

    , - -. , - Pascal,Visual Basic, C, C++, Java , - .

    .

    , . .

    147

  • 7.1

    , , , , - .

    (-)

    (-)

    (-)

    (a-z)

    0-9

    + - * / = ^ ( ) . , ! &

    7.2

    , - .

    , , .

    . - . , - . 1, 3409, 0, -980.

    . . 3.14159,

    148

  • 2.71828, -112.45, 0.45 . - , .

    . . - . - , , , - 15 .

    -, . , - , -.

    . . .

    7.3

    (constants) - . , , , - .

    , - ( , ).

    149

    -1 = --1

    -2 = --2

    .

    .

    .

    - = --

    -

    -

    (bytes). -

    -

    -

    bytes

    . -

    -

    . -

    (integer)

    1, 2 4 bytes -

    (real) 4 8 bytes.

  • 150

    =3.14159

    =0.18

    =

    . , -.

    .

    , (- ) , - . - (-,-), (0-9) (underscore)(_), .

    , , , -, ., . .

    : ,, , _, 100, , , _-.

    : 100, , $.

  • 7.4

    (variable) .

    =

    () , - . , - .

    , .

    , - -. - .

    , - , - .

    , .

    , , , - .

    , -, , _, .

    151

    -1: --1

    -2: --2

    .

    .

    .

    -: --

  • , - , - , , .

    -, .

    7.5

    - : , , , .

    :

    152

    -

    -

    .

    : ,

    : ,

    :

    :

    .

  • +

    -

    *

    /

    ^

    DIV

    MOD

    7.6

    . :

    ()

    ()

    ()

    _()

    ()

    () ex

    A_M(X)

    _()

    7.7

    , - (expressions). - , , , . .

    , .

    153

    div -

    -

    , -

    mod .

    ..

    7 div 2 = 3 7 mod 2 = 1

  • , -, .

    , -

    1.

    2.

    3.

    a+1 a+1

    1/2 a3 1/2*a^3

    3 2x y

    a b

    +

    (3*x+2*y)/(a-b)

    2 2*()

    , . - . - . , . .. 2+3*4 14, (2+3)*4 20, .

    7.8

    - .

    154

    -

    -

    . -

    -

    -

    -

    .

  • - . , , -, .
  • - . (,). - , -. .

    -. , -, . . .

    . - - .

    156

    -

    ,

    - .

    -

    , , : ,

    - .

  • , -.

    7.10

    , . - , - . .

    -, .

    , - .

    , . _.

    (. . 10), _.

    . , &.

    (!), .

    . -

    , -

    . 18%.

    157

  • _

    !

    =0.18

    : , _,

    : _, _

    !

    _

    !

  • cost_fpa:=cost*fpa;

    total:=cost+cost_fpa;

    writeln ( , quantity, :,

    cost);

    writeln ( : , cost_fpa:7:0);

    writeln ( : , total:7:0)

    END.

    Basic

    fpa = .18

    INPUT : , Quantity

    INPUT : , Value

    Cost = Quantity * Value

    CostFpa = Cost * fpa

    Total = Cost + CostFpa

    PRINT ; Quantity; :;

    Cost

    PRINT USING H : ######; CostFpa

    PRINT USING : #######; Total

    END

    , , , - , , - , .

    :

    : , ,, .

    -.

    -.

    , ( ) - .

    159

  • .

    , , , , , - , -

    -

    . ;

    -;

    ;

    ;

    ;

    ;

    ;

    1. . , . , Pascal, ,1984.

    2. . , Basic: , , ,1991.

    3. . , QuickBasic , -, , 1992.

    4. R. Shackelford, Introduction to Computing and Algorithms,Addison-Wesley, USA, 1998.

    5. S. Leestma-L.Nyhoff, Turbo Pascal, Programming and Solving, McMillan,New York, 1990.

    6. N.Wirth, Systematic Programming: An introduction, Prentice Hall, 1973.

    160

  • http://www.swcp.com/~dodrill/

    - .

    http://www.progsource.com

    , , - : Pascal, Delphi, C/C++, Java, Perl, Visual Basic.

    www.cit.ac.nz/smac/pascal/default.htm

    Pascal -. , .

    http://www.cs.vu.nl/~jprins/tp.html

    , , , - Turbo Pascal.

    http://qbasic.com/

    , Qbasic.

    www.basicguru.com

    Basic. - , , - .

    (Usenet):

    comp.lang.pascalcomp.lang.pascal.misc Pascal

    alt.lang.basiccomp.lang.basic.misc Basic

    161

  • 8.

  • , . - - , , , - , - . , , - . - - . - .

    :

    , .

    () .

    .

    -.

    .

    .

    - : , .

    ;

    ;

    ;

    ;

    ;

    164

  • 8.1

    , . - - .

    - . -, - . , - , 0. , 0, , 0, .

    , , , , . , - . .

    - .

    = =0

    1

    > >10000

    >= + >= (+)/

    < ^2-4** < 0

  • , -.

    . - - .

    , .

    - , - .

    (=) (), .

    - , . - , , .

    0

  • ,

    >=0

    0

    _

  • >=0

    0

    _

  • - .

    , - , , .

    ...... .

    ,,,,,,,

    ,

    < 80

    < 1.70

    ,

    _

    _

    ,,,,,

    .

    , __, .

    ,,,,,,,

    ,

    < 80 < 1.70

    ,

    _

    ,,,,,

    ......_

    169

  • 170

    -1

    -1

    -2

    -

    _AN -2

    -1

    -2

    -

    -1

    -2

    -

    _

    > 0

    -

  • 1

    ( -

    )

    . -

    .

    1-50 200,000

    51-100 180,000

    101-200 160,000

    200 150,000

    :

    =

  • . .

    , -:

  • -.

    - .

    8.2

    , , - . - , - .

    , - - , _ - - , - .

    8.2.1 ...

    ... . , - -, .

    173

    1,3,5,7,9

    2,4,6,8

    < 0 >9

    _

    . , .

  • ... - . - , .

    , , . - .

    2

    , ,

    .

    0.

    174

    -1

    -2

    -

    _

  • :, ,

    :

  • ... -_ . _ -. - , _.

    _ - .

    176

    _

    -1

    -2

    -

    _ -

    _

    = 1000

    _ -_. ( ), _- _, . , - .

    _.

  • 3

    , . ,

    ( ).

    2

    :, ,

    :

    :

  • BEGIN

    count:=0;sum:=0;

    REPEAT

    REPEAT

    write( :);

    readln (x);

    IF x0;

    sum:=sum+x;

    count:=count+1;

    write( ;);

    readln(choice);

    UNTIL (choice=o) OR (choice=O);

    avg:=sum/count;

    writeln(: , sum:5);

    writeln( : ,avg:6:2);

    END.

    8.2.3 ......

    , . - -, . , . - -, ( - _). . , . - , -, _.

    , 1, -.

    178

    ......

    -

    -

    .

  • 4

    -

    100.

    :,

  • .

    :

    -. , .

    .

    - .

    5

    -

    .

    ! 1 10

    :,,

    !:

    !:

    !:

    1 10

    1 10

  • PRINT

    NEXT a

    END

    -.

    - , , . .

    : _. .

    . , - _ . , - . , _ .

    , , ,

    -

    1. ;

    2. ; ;

    3. ;

    4. - - -_;

    5. ;

    6. ;

    181

  • 7. ;

    8. _;

    9. ;

    10. -;

    1. . , Pascal, , -, 1997.

    2. . -. , Turbo Pascal, -, 1996.

    3. . , QuickBasic , -, , 1992.

    4. R. Shackelford, Introduction to Computing and Algorithms,Addison-Wesley, USA, 1998.

    5. S. Leestma-L.Nyhoff, Turbo Pascal, Programming and Solving, McMillan,New York, 1990.

    6. N.Wirth, Systematic Programming: An introduction, Prentice Hall, 1973.

    http://www.swcp.com/~dodrill/

    http://www.progsource.com

    www.cit.ac.nz/smac/pascal/default.htm

    http://www.cs.vu.nl/~jprins/tp.html

    http://qbasic.com/

    www.basicguru.com

    182

  • 9.

  • -. , - .

    .

    , - , -, , .

    .

    .

    , .

    .

    .

    .

    -, ;

    -;

    ;

    - ;

    184

  • 9.1. .

    - , .

    , , - - .

    , 30, ,

    .

  • , - .

    -. , 9.1.

    , .

    , [ ]. [2], , 27.

    [i] i- .

    -, , , , . . - .

    186

    . 9.1.

    -

    -

    .

    -

    -

    i, j, k.

  • : [30]

    , - . . - .

    1

    -

    : [30], ,

    : i,

  • ,
  • i 1

    ,i,-

    [i]

    _

    !

  • Basic

    DEFINT A-Z

    DIM x(100)

    CLS

    sum = 0: sum2 = 0

    INPUT N=, n

    FOR i = 1 TO n

    PRINT ; i; - : ;

    INPUT , x(i)

    NEXT i

    FOR i = 1 TO n

    sum = sum + x(i)

    sum2 = sum2 + x(i) ^ 2

    NEXT i

    mt! = sum / n

    ta! = SQR(sum2 / n - mt! ^ 2) ..

    FOR i = 2 TO n

    FOR j = n TO i STEP -1

    IF x(j - 1) > x(j) THEN SWAP x(j - 1), x(j)

    NEXT j

    NEXT i

    IF n MOD 2 = 0 THEN

    median = (x(n / 2) + x(n / 2 + 1)) / 2

    ELSE

    median = x((n + 1) / 2)

    END IF

    PRINT

    PRINT =======================

    PRINT =; n

    PRINT =; mt!

    PRINT =; ta!

    PRINT =; median

    END

    190

  • 9.2.

    , - .

    , .

    . . - - .

    . - , 100. - , .

    - .

    , , - . .

    .

    . - , . , - , . - , .

    9.3.

    30 , -

    191

  • 30 , . .

    .

    1 2 10

    1 25 21 32

    2 26 22 31

    . .. .. .. ..

    30 27 23 30

    30 - , 300 . , , . - 27.

    , ( ) ( ). [30,1] 27.

    -[i,j] i j -, i 1 30 j 1 10. 3010.

    3

    ( 30 -

    10 ). , , -

    .

    192

  • _2

    : [30,10], [10]

    : i, j, ,

    !

    i 1 30

    j 1 10

    , i, j

    [i,j]

    _

    _

    !

    j 1 10

  • BEGIN

    FOR i:=1 TO 30 DO

    FOR j:=1 TO 10 DO

    BEGIN

    write ( :,i,j, );

    readln (temperature[i,j])

    END;

    FOR j:=1 TO 10 DO

    BEGIN

    total:=0;

    FOR i:=1 TO 30 DO

    total:=total+temperature[i,j];

    ave[j]:=total/30

    END;

    FOR j:=1 TO 10 DO

    BEGIN

    days:=0;

    FOR i:=1 TO 30 DO

    IF temperature[i,j] < ave[j] then

    days:=days+1;

    writeln ( ,i,

    ,ave[i]:4:1);

    writeln ( :,

    days);

    END

    END.

    - , , - . - -.

    , . - . , . , 25 [1,1,1].

    194

  • 4.

    :

    . -

    .

    . -

    ,

    .

    . -

    , .

    -. , . , - , , .

    :

    195

    2001

    1 2 10

    1 25 21 32

    2 26 22 18 31

    . .. .. .. ...

    30 27 23 18 30

    2000

    1 2 10

    1 25 21 32

    2 26 22 18 31

    . .. .. .. ...

    30 27 23 18 30

    1999

    1 2 10

    1 25 21 32

    2 26 22 31

    ... ... ... ...

    30 27 23 30

  • 1. - , .

    2. , - .

    3. - , .

    . , .

    : [10,7], i,j, , ,

    : [10]

    !

    i 1 10

    ,i,

    [i]

    j 1 7

    , j,-

    [i,j]

    _

    _

    !

    !

  • .. ,, ,[]

    !

    !

  • writeln( , name[i], = , sum);

    IF max

  • , - .

    :

    .

    . .

    .

    - . -, , - . , - .

    .

    3 -, 2.

    -. .

    , - .

    .

    :

    , - . . - .