In programming, algorithm is a set of well defined instructions in sequence to solve the problem.
Qualities of a good algorithm
- Input and output should be defined precisely.
- Each steps in algorithm should be clear and unambiguous.
- Algorithm should be most effective among many different ways to solve a problem.
- 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
- It is a step-wise representation of a solution to a given problem, which makes it easy to understand.
- An algorithm uses a definite procedure.
- It is not dependent on any programming language, so it is easy to understand for anyone even without programming knowledge.
- Every step in an algorithm has its own logical sequence so it is easy to debug.
- 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.
- Writing algorithm takes a long time.
- An Algorithm is not a computer program, it is rather a concept of how a program should be.
Flowchart ->A 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->
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
Advantages of flowchart:
- The Flowchart is an excellent way of communicating the logic of a program.
- It is easy and efficient to analyze problem using flowchart.
- During program development cycle, the flowchart plays the role of a guide or a blueprint. Which makes program development process easier.
- 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.
- It helps the programmer to write the program code.
- 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
- The flowchart can be complex when the logic of a program is quite complicated.
- Drawing flowchart is a time-consuming task.
- 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.
- 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.
- In the case of a complex flowchart, other programmers might have a difficult time understanding the logic and process of the flowchart.
- It is just a visualization of a program, it cannot function like an actual program