본문 바로가기

[이산 수학] - Discrete Mathematics/[Concept]

Chapter 4.1 ~ 2

Algorithms

 

2+2+...+2 = 200  vs  2*100 = 200

 

Pseudocode

 

i) let = denote the assignment operator.

x = y means "copy the value of y into x"

x = y is executed, the value of y is unchanged.

 

ii) Example

 

if(y>x)

    z = x

y = z


if(y==x)

    z = x

y = z

 


if(y ㄱ= x)

    y = x

else

    z = x

a = z

 


if(y < x)

    y = x

else 

    z = x

a = z

 


large = s1

i = 2

while(i <= n){

    if(si > large)

        large = si

    i = i + 1

}

 


large = s1

for i = 2 to n

    if(s1 > large)

        large = si

 


max2(a,b,c){

    x = a

    if(b > x)

        x = b

    if(c > x)

        x = c

    return x

}

 


max(s,n){

    large = s1

    for i = 2 to n

        if(si > large)

              large = si

    return large

}

 


p ( index 1 to m), t (index 1 to n), i , j

 

for i = 1 to n-m+1 {

    j = 1

    while( t(i+j-1) == p(j) )

    {

        j += 1

    if( j > m )

        return i

    }

}

return 0