Chapter 1 | Introduction to Programming Concepts - Part 2 |
Tools Used in Problem-Solving
As seen earlier, a program is a set of instructions for solving a particular problem.
Before we actually start writing a program we need to derive a procedure for solving the problem An algorithm is a sequence of steps required to solve a problem. The word algorithm is derived from the name of the Arab mathematician, Al-Khowarizmi (825 AD).
For example, for preparing a cup of tea, the algorithm will be:
- Step 1: Take water, sugar, and tea leaves in a utensil.
- Step 2: Put the utensil on flame.
- Step 3: When the mixture boils switch off the flame.
- Step 4: The tea is ready.
An algorithm follows the I-P-O cycle to solve the problem. Here, the input for preparing tea would be the ingredients like water, sugar, tea leaves, and milk. These ingredients are then boiled, which means processing takes place, and at the end of the process, the tea, which is the output, is prepared.
According to D.E. Knuth, a pioneer in the field of computer science, an algorithm has the following five 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 an algorithm specify basic operations. These operations could include calculations, input/output operations, and comparisons.
- An algorithm accepts input data, in a defined format, before it can be processed.
- An algorithm generates one or more outputs after the input is processed. The resultant information termed as output can be displayed or stored for future reference.
Levels of Algorithm
An algorithm may contain either brief or detailed steps. Therefore, an algorithm may have two levels, macro and micro. An algorithm that contains brief steps about a process is called a macro-level algorithm, while an algorithm that contains detailed steps about a process is called a micro-level algorithm.
For example, a television company may provide the following macro-level algorithm in the television manual to troubleshoot the âNo soundâ problem:
- Step 1: Begin.
- Step 2: Ensure that the Mute button is not pressed.
- Step 3: Ensure that the desired volume is set.
- Step 4: If sound is still inaudible, call the television engineer.
- Step 5: End.
Instead of the preceding macro-level algorithm, a television company can also provide the following micro-level algorithm for solving the same problem:
- Step 1: Begin.
- Step 2: If the Mute symbol appears on the television screen, take the remote control and press the Mute button on the Remote control to set the sound on.
- Step 3: If still there is no sound, increase the volume using the volume control of the remote control.
- Step 4: If sound is still inaudible, call the television engineer.
- Step 5: End.
Apart from writing algorithms, the steps to solve a problem can also be represented using tools such as:
- Pseudocode
- Flowcharts
Pseudocode
Pseudocode is a detailed yet readable description of what an algorithm must do, expressed in a formally-styled natural language rather than in a programming language. Pseudocode is used as an initial step in the process of developing a program. It provides programmers a detailed template for writing instructions in a specific programming language.
Advantages of Pseudocode
The advantages of using pseudocode are:
- It is easier and faster to write as it uses English like statements.
- It does not need to be rewritten if any changes are made because each step is independent and may be modified without altering the other steps.
- It can be converted to a program using any programming language. This is because the format used by pseudocode is similar to a program. They both contain a set of sequential statements using a defined set of keywords.
Limitations of Pseudocode
The limitations of using pseudocode are:- Pseudocode does not provide a graphical representation of an algorithm; therefore, it might be difficult to understand the complex logic in a pseudocode.
- Pseudocode depicting too many nested conditions may be difficult to understand.
Flowcharts
A flowchart is a graphical representation of an algorithm. It consists of a set of symbols. Each symbol represents a specific kind of activity depicted in the algorithm. A typical problem would involve accepting input, processing the input and displaying the output. The processing would involve the computations and the decisions that are being taken.Advantages of Flowcharts
Flowcharts offer many advantages. Some of these advantages are:- Flowcharts are a better method of communicating logic than pseudocode and decision tables.
- Flowcharts help in analyzing the problems effectively.
- Flowcharts act as a guide during the program development phase.
- It is easier to debug errors in logic using a flowchart.
- Flowcharts help in maintaining the programs because programmers can easily understand the logic.
Disadvantages of Flowcharts
Although flowcharts provide several advantages, they have a few disadvantages as well. Some of these disadvantages are:- A lengthy flowchart may extend over multiple pages, which reduces readability.
- Drawing a flowchart using any graphical tool is a time consuming process.
- The changes made to a single step may cause redrawing the entire flowchart.
- A flowchart representing a complex algorithm may have too many flow lines. This reduces readability. In addition, it is very time-consuming to draw such flowcharts.
Summary
In this chapter, you learned that:- The cycle of activities performed by a computer follows the Input-Process-Output cycle.
- A set of instructions to perform a particular job is called a program.
- In a computer, everything is represented as a combination of on and off states. The on state is represented by â1â and the off state by â0â.
- The language that the computer understands is called the machine language.
- Programming languages have a vocabulary, which is referred to as the set of keywords of that language, and a grammar, which is referred to as the syntax.
- A compiler is a special program that processes statements written in a particular programming language and converts them into the machine language.
- An algorithm is a sequence of instructions in English language to solve a given problem.
- An algorithm is represented using tools such as pseudocode and flowchart.
- A pseudocode is an English like representation of an algorithm.
- A flowchart is a graphical representation of the steps to be followed for solving a problem.
No comments:
Post a Comment