Sunday, May 19, 2013

Algorithm Design


Algorithm - a set of instructions independent of any programming language that calculates a function or solves a problem.

Express the solution to a simple problem as an algorithm using flowcharts, pseudo-code or structured English and the standard constructs:

performing or operating each step consecutively in the order they arise
Console.writeline("This is line 1")
Console.writeline("This is line 2")
Console.writeline("This is line 3")

Assignment [edit]

Assigning a value to a variable
Dim x, y, sum as integer
x = 5
y = 15
sum = x + y

Selection [edit]

Selection is choosing a step
If-Then-Else-diagram.svg

If x > 0 then
   Console.writeline("x is positive")
End If
If x = 0 then
   Console.writeline("x equals 0")
End If
If x < 0 then
   Console.writeline("x is negative")
End If

Repetition [edit]

A sequence of steps that loop until a requirement is met
Do-while-loop-diagram.svg

While-loop-diagram.svg

CPT-For-loop-diagram-complex.svg
x = 0
y = 5
Do
   x = x + 1
Loop Until x = y

wikiBooks

No comments:

Post a Comment