Note on Pseudocode and Algorithm

  • Note
  • Things to remember

Programming Tools

During programming analysis and system design, the programmers, system engineers and system designers work together to build a successful program or a computer-based information system. Various ideas, components and program modules are integrated to accomplish the task.

System analysts and designers perform the following tasks during these steps.

  1. Selection of programming language
  2. Selection of the programming tools
  3. Design and virtual testing of the program.

The programming tools give the idea how the flow should take place in order to accomplish a task. Several programming tools are used in this context. Some of the most common programming tools are:

  1. Pseudo code
  2. Algorithm
  3. Flowchart

Pseudo code

Pseudo code is a combination of two words: Pseudo and Code. 'Pseudo' means imitation and 'code' refer to instruction written in the programming language. Pseudo code is not a real programming code. It is the generic way of describing an algorithm without using any specific programming language-related notations.

.

Source: www.slideshare.net

The features of pseudocode are:

  • It uses plain english statements.
  • It emphasizes on the design of the computer program.
  • It uses structured english.
  • It is detailed and readable to draw an inference.
  • It enables the programmers to concentrate on the algorithms.

The pseudo code cannot be compiled. It cannot be executed and there are no real formatting or syntax rules for writing pseudo codes.

It is simply an important step in producing the final code. Some important terms used in pseudo code for different activities are:

  • Input: Read, Obtain, Get and Prompt
  • Output: Print, Display, and Show
  • Computer: Computer, Calculate, and Determine
  • Initialize: Set and Initialize
  • Add one: Increment

The two major constructions in pseudo code structures are: Sequence and Selection (decision). Sequence indicates the continuous flow of the program, whereas selection uses logical comparison or conditional check for making decisions.

Example:

……………

IF (condition> THEN

List of Actions

ELSE

List of Different Actions

END IF

………………

…………………

Example:

READ A, B, AND C

IF A is greater than C THEN

DISPLAY A

ELSE

DISPLAY C

END IF

ELSE

IF B is greater than C THEN

DISPLAY B

ELSE

DISPLAY C

END IF

END IF

STOP

Example:

INITIALIZE Count to zero

DO WHILE Count is greater than or equal to 10

ADD 1 to Count

PRINT Count

ENDDO

STOP

Advantages of Pseudo code:

  1. Since, it is language independent, it can be used by most programmers.
  2. It helps to design in plain natural language.
  3. It is easier to develop the program from pseudo code than with a flowchart.
  4. It is easy to translate to the programming language.
  5. Its simple structure and readability makes it easier to modify as well.

Disadvantages of Pseudo code:

  1. It does not provide the visual representation of the program logic.
  2. There are no accepted standards for writing pseudo code.

Algorithm

An algorithm is defined as a finite sequence of explicit instructions that produces an output with the set of input values. The steps in the algorithm are never ambiguous. It terminates after a finite number of steps.

.

Source:www.brandxindustries.com

Algorithms can have repetitions and logical decisions until a specific task is completed. Algorithms are not computer programs. They cannot be executed by the computer.

Properties of Algorithm

An algorithm must have the following properties.

  1. There should not be any ambiguity in instructions.
  2. The instructions should be specific to the task.
  3. The description of an algorithm must be finite. It cannot be open-ended.
  4. The algorithm must be general enough for writing programs.
  5. As far as practicable, program codes should not be included in algorithms.

Example: Write an algorithm to make a telephone call.

Step 1: Remember or read the telephone number.

Step 2: Lift the receiver

Step 3: Is there a dial tone?

If yes, then dial telephone, go to step 4.

{ If no, then put down the receiver.

Go to step 2}

Step 4: Speak

Step 5: Put down the receiver.

Example: Write an algorithm to find the largest number among three input numbers.

Step 1: Start

Step 2: Read 3 numbers say: A, B, C

Step 3: Find the largest number between A and B and store it in MAXAB

Step 4: Find the largest number between MAXAB and C and store it in MAX

Step 5: Display MAX

Step 6: Stop

Write the algorithm to calculate the interest on principle amount in N number of Years.

Step 1: Start

Step 2: Read principle, Rate and Time

Step 3: Multiply principle * Rate * Time

Step 4: Divide by 100

Step 5: Write the answer

Step 6: Any more calculations?

{ If yes, then go to step 2

If No }

Step 7: Stop

Write algorithm to calculate the total and average marks of 10 students for 7 subjects.

Step 1: Start

Step 2: Subject = 1

Step 3: Input mark for this Subject

Step 4: Add marks and store into a variable

Step 5: Are all subjects (7 subjects) done?

{ If No, then increase the subject number and go to step 3.

If yes, then go to step 6

Step 6: Print the sum

Step 7: Find average (divide by 7)

Step 8: Print the sum and average

Step 9: Are all (10 students done)?

{ If No, then increase the student number and go to step 2

If yes, then go to step 9}

Step 9: End

References:

Khanal, R.C. Khanal, R.C. Computer Concept for XII. Pashupatigriha Marga, Thapathali, Kathmandu, Nepal: Ekta Books Distributors Pvt. Ltd., 2010. 117-123.

Adhikari, Deepak Kumar.,et.al., Computer Science XII,Asia Publication Pvt.Ltd

  1. The programming tools give the idea how the program flow should take place in order to accomplish a task.
  2. Pseudo code Algorithm and Flow Chart are the example of various programming tools.
  3. Pseudo code means imitation and code refer to instructions written in the programming language.
  4. Pseudo code is not real programming code.
  5. It is the generic way of describing an algorithm without using any specific programming language related notations.
  6. An algorithm is defined as a finite sequence of explicit  instructions that produces an output with the set of input values. 
.

Very Short Questions

0%

DISCUSSIONS ABOUT THIS NOTE

No discussion on this note yet. Be first to comment on this note