Sei sulla pagina 1di 18

ALGORITHM DESIGN

ALGORITHM
Is an effective procedure for solving a problem in a finite number of steps . Is an outline to a problem solution It shows the precise order in which the program will execute individual functions to arrive to a solution. It is language independent There are different ways of expressing an algorithm, but well focus only in pseudocode and flow charts.

Algorithms show these three features: Sequence (also known as Process) Decision (also known as Selection) Repetition (also known as Iteration or Looping) Strategies for designing an algorithm: Step 1: Investigation step - Identify the processes - Identify the major decisions - Identify the loops - Identify the variables

Step 2: Preliminary algorithm step - Devise a "high level" algorithm - Step through the algorithm. Does this "walkthrough" reveal any major problems? If it does correct the problems.

Step 3: Refining the algorithm step - Incorporate any refinements indicated in step 2. - Group together processes where appropriate - Group together variables where appropriate - Test the algorithm again by stepping through it

PSEUDOCODE

Pseudocode and flowcharts are programmer's ways of expressing algorithms, control structures, and other programming concepts quickly and simply. Pseudocode is a kind of structured english for describing algorithms. It is programming language independent. Pseudocode cannot be compiled nor executed, and there are no real formatting or syntax rules

Example 1: Write a pseudocode that obtains two integer numbers from the user. It will print out the sum of those numbers. Pseudocode: READ user's first and second integers ADD first integer and second integer STORE the result in another variable, sum DISPLAY sum

Example 2: Write a pseudocode that obtains two integer numbers from the user. It will print out the largest numbers. Pseudocode: READ the first and second integers IF first integer > second integer THEN DISPLAY first integer ELSE DISPLAY second integer END IF

Example 3: Write a pseudocode that calculates the value of a according to the following equations: a = x*y*z (when x=1), a = x / z (when x=3), a = x*y / z (when x=5) Pseudocode: READ the values of x, y, z SELECT CASE (based on values of x) when x=1: a=x*y*z when x=3: a=x / z when x=5: a=x*y /z END SELECT CASE DISPLAY value of a

Example 4: Construct a pseudocode to read a series of numbers, stop reading numbers when the value is zero, and display its average. Pseudocode: SET count= 0, sum= 0 READ the number, x sum = sum + x count = count + 1 DOWHILE x<>0 READ the number, x sum = sum + x count = count + 1 END DOWHILE average= sum/count DISPLAY average

FLOW CHARTS - is a pictorial representation of a pseudocode.


A Flowchart is used for: defining and analyzing processes building a step-by-step picture of the process for analysis, discussion, or communication purposes defining, standardizing, or finding areas for improvement in a process

Steps for creating a flowchart are: Familiarize the participants with the flowchart symbols Brainstorm major process tasks. Ask questions such as "What really happens next in the process?", "Does a decision need to be made before the next step?", or What approvals are required before moving on to the next task?" Draw the process flowchart using the symbols on a flip chart or overhead transparency. Every process will have a start and an end (shown by elongated circles). All processes will have tasks and most will have decision points (shown by a diamond).

Analyze the flowchart for such items as: - Time-per-event (reducing cycle time) - Process repeats (preventing rework) - Duplication of effort (identifying and eliminating duplicated tasks) - Unnecessary tasks (eliminating tasks that are in the process for no apparent reason) - Value-added versus non-value-added tasks Example 1: Write a flow chart that obtains two integer numbers from the user. It will print out the sum of those numbers

Flow chart:

Start

Accept first and Second numbers

Add first and second numbers

Print sum

End.

More examples:*(CLASS WORK)* Refer to examples 2 to 4 (of pseudocode), develop their flow charts .

TEST DATA AND DESK CHECK

DESK CHECK

Desk checking is a manual (non computerized) technique for checking the logic of an algorithm. A Desk Check concentrates on the value of variables and the logic i.e. what is the value of variable x after statement n; what is the next statement to be executed?

Desk checks are useful to check an algorithm (before coding) thereby confirming that the algorithm works as expected and saves time possibly writing a program that doesn't do what was intended. Another benefit of a desk check is that it confirms to the programmer/ designer that the algorithm performs as intended.

TEST DATA

Focuses on the values of inputs and outputs required to test a program without concern for the internal workings i.e. are the results (outputs) correct for the inputs?. Simulated transactions that can be used to test processing logic, computations and controls actually programmed in computer applications. This technique includes Integrated Test Facilities (ITFs) and Base Case System Evaluations (BCSEs).

Potrebbero piacerti anche