Pages

Translate

Monday, 18 June 2012

Guidelines For Writing Algorithms,Pseudocode And Flowcharts

Here are a few guidelines that will help you in writing an efficient algorithm:

  • An expected output should be decided by the programmer before writing an algorithm.
  • Each step in an algorithm should be written clearly,stating each task to be performed.
  • To be sure that the algorithm produces the expected output,it should be checked using sample values.
And a couple too for writing pseudocode,

  • Statements that are related should be combined to avoid writing a lengthy pseudocode. For example,
          display "Enter first number"
          accept number1
          display "Enter Second number"
          accept number2

The statements above make the for a lengthy pseudocode,it can be shortened by combining the statements. For example:
         display "Enter two numbers"
         accept number1,number2

  •  The pseudocode should be aligned properly for a clear understanding of the steps carried out.
Here are also rules recommended by the American National Standard Institute (ANSI) that are to be followed when drawing a flowchart.

  • The entire logic of a flowchart should be represented using standard symbols.
  • The flowchart should be clear,precise and easy to follow.
  • The flowchart should have only one start point and one end point.
  • The steps in a flow chart should follow top-to-bottom or left-to-right approach.
  • All necessary inputs should be listed in logical order.
  • The start and stop symbols should have only a single flow line.
  • The input,process,output and display symbols should have at least two flow line connecting to the previous symbol and to the next symbol.
  • The decision symbol should have one flow line flowing into it and two flow lines flowing out of it for each possible decision.
  • Flow charts should use page connectors if they extend over multiple pages.
  • It is useful to text the logic of the flowchart by texting the flowchart using some sample values.........


Monday, 11 June 2012

Tools Used In Problem Solving (Pseudocode & Flowcharts)

Carrying on from where i left off with the last post where i talked about algorithm,i'll be looking at pseudocode and flowcharts. Two more tools used in problem solving when it comes to Logic building.

PSEUDOCODE:
The pseudocode is a detailed readable description of what an algorithm must do,expressed in a formally styled natural language rather than a programming language.
It is easy and fast to write since it uses english statements and can easily be converted to a program using any programming language but it might also be difficult to understand the complex logic in a pseudocode as it does not provide a graphical representation of an algorithm like the flowchart does.

FLOWCHARTS:
A flowchart can simply be defined as the graphical representation of an algorithm. It uses symbols to represent the activities depicted in an algorithm. It also requires the I-P-O cycle to solve problems,but here the processing would involve the computations and the decisions that are been taken.
The flowchart helps in analyzing the problems effectively and act as a guide during the program development phase. However it can be time consuming and a lengthy flowchart may extend over multiple pages which reduces readability. One should also be carful to avoid mistakes as a change made to a single step may cause redrawing the entire flow chart.
One will know the symbols used when preparing a flow chart and their meanings if your familiar with microsoft office.
Here's an example of an algorithm that displays the sum of two numbers presented in both pseudocode and flowchart.

ALGORITHM                                           PSEUDOCODE PRESENTATION
STEP 1:Start the algorithm                          Begin
STEP 2:Get the first number                            Accept firstnumber
STEP 3:Get the second number                       Accept secondnumber        
STEP 4:Add the two numbers                         Compute sum as firstnumber +
STEP 5:Display the result                                + secondnumber
STEP 6:End the algorithm                               Display Sum
                                                                  End
FLOWCHART PRESENTATION


.
Please it should be noted that these examples i've given are without variables.....till next time.

Wednesday, 6 June 2012

Logic Building: Tools Used For Problem Solving (Algorithm)

We already know what programs and programming languages are from my last post. Now we'll talk about problem solving. The procedures to solve a problem can be represented by using any of these:

  • Algorithm
  • Flowchart
  • Pseudocode
ALGORITHM: When we hear algorithm,numbers and calculations are the first things that come to mind right?. It's quite the opposite,an algorithm is a sequence of steps required to solve a problem,it is a list of well defined instructions to solve a given problem.Here's an example of an algorithm that displays the subtraction of two numbers:


STEP 1: Start the algorithm
STEP 2: Get the first number
STEP 3: Get the second number
STEP 4: Subtract the two numbers
STEP 5: Display the result
STEP 6: End the algorithm


Of the three procedures used in problem solving,the algorithm is quite simply the easiest one.The algorithm follows the I-P-O cycle to solve a problem. Here the inputs are the numbers,these inputs are accepted and then the process of subtraction takes place. When the processing is done,the result which is the output is then displayed.
According to D.E Knuth,an algorithm should have the following characteristics:

  • An algorithm ends after a fixed number of steps.
  • Each step in an algorithm clearly specifies the action to be performed.
  • The steps in algorithm specifies basic operations,these could include calculations,input/output operations and comparisons.
  • An algorithm accepts input data in a defined format before it can be processed.
  • An algorithm can generate one or more outputs after the input is processed. The resulting information termed as output can be displayed or stored for further references.
I will talk about Pseudocode and Flowcharts in my next post.......Until Then........