Sunday, August 10, 2014

ALGORITHMS AND FLOWCHART

Algorithms
         Computing problems
        Can be solved by executing a series of actions in a specific order
         An algorithm is
        A procedure for solving a problem in terms of
         The actions to be executed, and
         The order in which these actions are executed
         Program control is
        Specifying the order in which statements are to be executed
         
Pseudocodes
         A pseudocode is
        An artificial and informal language that helps programmers develop algorithms
        Similar to the natural language
        Not an actual programming language
        Not actually executed on computers
         Why do you need it?
        Helps to “think out” a program before writing it
        May be converted easily into a corresponding C program
 An Example:

Pseudocode for calculation of grade of students
Input the marls of student
if student’s mark is greater than or equal to 90
     print “A”
else
     if student’s mark is greater than or equal to 80
          print “B”
     else
          if student’s mark is greater than or equal to 70
              print “C”
          else
              if student’s mark is greater than or equal to 60
                   print “D”
              else
                   print “F”


Flowcharts
         A flowchart is
        A graphical representation of an algorithm, or of a portion of an algorithm
        Useful for developing and representing algorithms
        Drawn using certain special-purpose symbols connected by arrows called flowlines
         Symbols indicate the actions to be performed, and flowlines indicate the order in which actions are to be performed

Flow chart symbols


Flow chart symbols
                         
Symbol
Description


Oval symbol (or termination symbol) indicates the beginning or end of a program, or a section of code

Rectangle symbol (or action symbol) indicates any type of processing, calculation
Subprocess symbol used for pre-defined process

Parallelogram symbol
For input/output operation


Diamond symbol (or decision symbol) indicates that a decision is to be made

Flowline connects one symbol to another

Entry or exit points are used to attach the one flowchart to another

The flow chart equivalent to the above pseudocode




                                              



Using flow charts to design programs

The algorithm sums all the even numbers between 1 and 20 inclusive and then displays the sum. It uses a repeat loop and contains a null else within the repeat loop.


The equivalent pseudocode is: 
1. sum = 0 
2. count = 1 
3. REPEAT 
   IF count is even THEN
 sum = sum +  count 
   count = count + 1 
   UNTIL count >20 
4. DISPLAY sum

We can see quite clearly from this example what the price of flow charting is. There is quite a bit of drawing to do in addition to writing the legend in the symbols. The pseudocode is quite simple by comparison so why would you use flow charts?




The major reasons are that the flow chart.
  • is easier to read
  • more closely follows a standard, this is not the the case with pseudocode
  • easier to understand than pseudocode


We can see quite clearly from this example what the price of flow charting is. There is quite a bit of drawing to do in addition to writing the legend in the symbols. The pseudocode is quite simple by comparison so why would you use flow charts?
The major reasons are that the flow chart.
  • is easier to read
  • more closely follows a standard, this is not the the case with pseudocode
  • easier to understand than pseudocode

 

HackerBoy

Compiled By Sabin Khanal

0 comments:

Post a Comment

 

Copyright @ 2013 Learn Programming.

Designed by Templateiy & CollegeTalks