October 24, 2021

TECH HYME

A Blog For Tech Enthusiasts

Brief Overview of Algorithms and Flowcharts

2 min read

An algorithm may be defined as the step-by-step procedure or method that can be carried out for solving programming problems. Or an algorithm consists of a set of explicit and clear (only one meaning) finite steps, which when carried out for a given set of initial conditions, produce the corresponding output and terminate in a fixed amount of time. An algorithm tells computer how to solve problem systematically to get desired output.

Write an algorithm for having lunch at a restaurant.

The steps of this problem can be defined as follows:

  • Step 1: Sit in car with your parents.
  • Step 2: Reach the Restaurant.
  • Step 3: See the menu card.
  • Step 4: Order the food.
  • Step 5: Eat the food.
  • Step 6: Pay for the bill.

Similarly steps for a computer problem can also be defined. An algorithm to calculate and display area of a triangle.

The steps are as follows:

  • Step 1: Input values of sides of the triangle.
  • Step 2: Apply the formula to calculate the area of the triangle.
  • Step 3: Print the result

Characteristics of Algorithms

  • Problem should be solved in finite number of steps.
  • Algorithms should be simple and easy to read.
  • Problems should be solved in finite number of step-by-step direction.
  • It should be universal and leads to a unique solution of the problems.
  • It should be capable of handing exception.
  • It should be precise and unambiguous.
  • It should be provide result in finite amount of time.
  • It must be complete and correct.
  • Desired result must be obtained after execution.

How to write an Algorithm

There are different steps that should be in mind when you have to write algorithms for solving a particular type fo problems.

Steps to Write Algorithms

  1. Take input from the user. The input is processed in subsequent instruction in the algorithms.
  2. Process the input data entered by the user.
  3. Produce one or more output after processing.
  4. Show result.

Three basic Control Structures

The three main control structures which are necessary for writing are algorithm can be defined as follows:

1. The Sequence Structure:

In sequence control structure, the series of steps are executed serially and sequentially one after another.

TECH Hyme FLowcharts and Algorithms

2. The selection Structure:

The selection structure is built around the condition statement. Result action depends upon whether the condition is true or false. When the condition is met, control goes to the true branch otherwise it goes to the false branch.

For example:

If<having exams>THEN<Do Study>ELSE<GO
If<Temperature>37CTHEN<Switch on
AC>ELSE<Switch on fan>

TECH Hyme FLowcharts and Algorithms

3. The Repetition Structure (Iteration or Loop)

Repetition structure is also based on certain condition. While the condition is true. we keep on repeating a block of instruction until the condition becomes false. For example, you are feeling thirsty and drinking water to quench your thirst. You keep on drinking the water till you no longer feel thirsty. This repetition structure can be represented by a loop.

Example – To drink water till you no longer feel thirsty

TECH Hyme FLowcharts and Algorithms

Checking the Algorithms

To ensure the efficient execution of the program it is necessary to check the algorithms before coding it. There are many different methods to check the algorithms. Some of them are:

  • DRY RUN: This is the manual way of examining the algorithms. In this method we find the value of each variable after every step of algorithm.
  • REVIEW: This method involves studying the logic and computing it with a specification.
  • WALK THROUGH: In this method, algorithm is present to the team member for checking the efficiency of an algorithms.

FLOW CHARTS

Flow chart is the pictorial representation of problem and algorithm to its solution that uses they symbols connected by flow lines.

The different symbols denote different types of instruction and flow lines represent process and the direction of the flow within the program. It is called flowchart because it charts the flow of program. The flowchart is basically used as an aid in expressing and understanding algorithm. The flowchart is quite useful for the programmer and the systems analyst.

Symbols used in the Flow Chart

There are different symbols that are used in flow chart. The symbols used in flow charts specify some meaning. These symbols have been adopted by the American national standard destitute. The important symbols used in flowchart are as follows:

1. The Terminator Symbol: The terminator symbol is represented by rectangle with rounded ends. It indicates the start and stop of the flow chart.

TECH Hyme FLowcharts and Algorithms

2. Input Output Symbols: The input output symbols are represented by parallelogram. It represents an input output operation in flowchart.

TECH Hyme FLowcharts and Algorithms

3. Decision Symbols: The decision symbol is represented by diamond. It is used to check condition whether it is true or false. Depending upon the condition the program branches into directions.

TECH Hyme FLowcharts and Algorithms

4. Process: The rectangle is used to represents processing. It indicates any processing operation such as calculation, processing and storage etc.

TECH Hyme FLowcharts and Algorithms

5. Connector Symbols: The connector symbols are represented by circle and it brings together two branches of the program. The connector connects various pages of long flowcharts, which are spread on many pages.

TECH Hyme FLowcharts and Algorithms

6. Predefined Process Symbols: It is used to represents a module of program that has been already defined by another flowchart.

TECH Hyme FLowcharts and Algorithms

7. Document: This represents any document on paper.

TECH Hyme FLowcharts and Algorithms

8. Dataflow Symbol: These symbols are used to indicate the flow of operation. A flow symbol also connects other symbols in a flowchart and the sequence of their execution. The default direction is from top to bottom and left to right, but if there is any reverse direction the arrow must be used.

TECH Hyme FLowcharts and Algorithms

9. Annotation Symbols: It represented by open-ended box connected to the charts by dotted lines. The annotation used for explanation or comments related to the program. It is actually used to add clarifying comments to other flowcharts symbols.

TECH Hyme FLowcharts and Algorithms

10. Preparation: The preparation symbol is used to control, initiate or perform some other operation on the program itself. Some programmers also prefer to use the preparation symbols rather than to use the generals processing symbols.

TECH Hyme FLowcharts and Algorithms

Convention Used For Drawing a Flowchart

There are number of rules and guidelines which helps to maintain standard in flow chart process. The following are the conventions used by various computer manufacture and data processing department in flowchart process.

  1. First design the main logic of the problems and then incorporate detail.
  2. It should contain only step-by-step graphical information and not every detail.
  3. Use common words and statement in flowchart symbol.
  4. Maintain consistent level in both the level of detail, in naming and variable.
  5. Crossing flow lines should be avoided.
  6. The direction of flow in any flowchart is from left to right to and top to bottom.
  7. The flowchart symbols may be drawn in any size, but the ratio should be maintained.
  8. Comments and cross-references may be provided when the meaning is not clear.
  9. Use connector if flowchart is on more than one page.
  10. Flowchart must be identified with title, and date and name of the author.

Advantages of Flowcharts

  1. Flowchart is the pictorial representation, so it provides an easy way of communication.
  2. It provides pictorial overview of the problem and its solution.
  3. It represents flow of data from top to bottom and left to right.
  4. It provides program documentation.
  5. It checks the accuracy.
  6. It also provides the facility to modify the program.
  7. It shows all the major elements in the flowchart and their relationship.
  8. It is quite useful in detecting and removing mistakes in a program.

Limitations of Flow Chart

  1. They take more time to draw with proper symbol for complex problems.
  2. It is difficult to modify.
  3. There is no standard for determining the amount of detail that should be included in a flow chart.

Leave a Reply