Unit-2:Algorithm and Flowchart


In programming, algorithm is a set of well defined instructions in sequence to solve the problem.

Qualities of a good algorithm

  1. Input and output should be defined precisely.
  2. Each steps in algorithm should be clear and unambiguous.
  3. Algorithm should be most effective among many different ways to solve a problem.
  4. An algorithm shouldn’t have computer code. Instead, the algorithm should be written in such a way that, it can be used in similar programming languages.

Examples Of Algorithms In Programming

Write an algorithm to add two numbers entered by user. Step 1: Start Step 2: Declare variables num1, num2 and sum. Step 3: Read values num1 and num2. Step 4: Add num1 and num2 and assign the result to sum. sum←num1+num2 Step 5: Display sum Step 6: Stop

Write an algorithm to find the largest among three different numbers entered by user. Step 1: Start Step 2: Declare variables a,b and c. Step 3: Read variables a,b and c. Step 4: If a>b If a>c Display a is the largest number. Else Display c is the largest number. Else If b>c Display b is the largest number. Else Display c is the greatest number. Step 5: Stop

Advantages of algorithm

  1. It is a step-wise representation of a solution to a given problem, which makes it easy to understand.
  2. An algorithm uses a definite procedure.
  3. It is not dependent on any programming language, so it is easy to understand for anyone even without programming knowledge.
  4. Every step in an algorithm has its own logical sequence so it is easy to debug.
  5. By using algorithm, the problem is broken down into smaller pieces or steps hence, it is easier for programmer to convert it into an actual program

Disadvantages of algorithm.

  1. Writing algorithm takes a long time.
  2. An Algorithm is not a computer program, it is rather a concept of how a program should be.

Flowchart ->flowchart is a type of diagram that represents an algorithm, workflow or process. The flowchart shows the steps as boxes of various kinds, and their order by connecting the boxes with arrows. … Flowcharts are used in analyzing, designing, documenting or managing a process or program in various fields.

Symbol of Flowchart->

Flowchart Symbols

Flowcharts use special shapes to represent different types of actions or steps in a process. Lines and arrows show the sequence of the steps, and the relationships among them. These are known as flowchart symbols.

Common Flowchart Symbols

  • Rectangle Shape – Represents a process
  • Oval or Pill Shape – Represents the start or end
  • Diamond Shape – Represents a decision
  • Parallelogram – Represents input/output
Basic flowchart symbols

Advantages of flowchart:

  1. The Flowchart is an excellent way of communicating the logic of a program.
  2. It is easy and efficient to analyze problem using flowchart.
  3. During program development cycle, the flowchart plays the role of a guide or a blueprint. Which makes program development process easier.
  4. After successful development of a program, it needs continuous timely maintenance during the course of its operation. The flowchart makes program or system maintenance easier.
  5. It helps the programmer to write the program code.
  6. It is easy to convert the flowchart into any programming language code as it does not use any specific programming language concept.

Disadvantage of flowchart

  1. The flowchart can be complex when the logic of a program is quite complicated.
  2. Drawing flowchart is a time-consuming task.
  3. Difficult to alter the flowchart. Sometimes, the designer needs to redraw the complete flowchart to change the logic of the flowchart or to alter the flowchart.
  4. Since it uses special sets of symbols for every action, it is quite a tedious task to develop a flowchart as it requires special tools to draw the necessary symbols.
  5. In the case of a complex flowchart, other programmers might have a difficult time understanding the logic and process of the flowchart.
  6. It is just a visualization of a program, it cannot function like an actual program