# 3 ways to Representing Solution of Problem

There are at least three different ways of representing a solution to any problem. There is a significant disconnect between requirements gathering and programming syntax. Directly converting this textual descriptive information into code is complex and error-prone.

The technique, also known officially as pseudo-code, aids in bridging the gap between description and programming syntax. It aids the programmer in the conversion of problems written in a loose language into programming language syntax. This allows for both reducing the risks of error and reducing the amount of time necessary for coding.

An algorithm is a simple type of program with no explicit syntactic requirements. Using his language, one may construct an algorithm.

## Different Ways of Representing Solution

Natural language

This is the easiest way of writing an algorithm. It contains English-like statements. This representation completely omits technical aspects of programming language syntax.

Pseudocode

This representation is very close to the generalized syntax of a programming language. It provides a clear depth of nested statements and repetition of statements. Pseudocode representation is a bridge between natural language representation and programming languages. It is more precise.

Flowchart

It is a graphical representation of the algorithm. It uses a standard set of symbols to represent the flow of operation.

## Example

Give natural language, pseudocode and flowchart representation of an algorithm to add elements of the array of size n.

All three different ways of representing a solution are discussed here:

Natural language representation

• Step 1 :   Read number n
• Step 2 :   Scan n elements in array A
• Step 3 :   Add all numbers of array A and store in the variable sum
• Step 4 :   Display the sum

Pseudocode representation

Algorithm SumArrayElements(A)
// Description: Algorithm adds digits of the input array
// Input: Array A of size n
// Output: Summation of all elements of array A

sum ← 0
for i ← 1 to n do
sum ← sum + A[i]
end

write “sum”

Flowchart representation

While solving the problem, the tendency to start writing code without designing an algorithm should be resisted. Time spent on the design and analysis of the algorithm helps in quick implementation.

## Short Questions:

### Q: Enlist different ways to represent a solution

We can represent a solution in three different ways:

• Natural language
• Pseudocode
• Flowchart

### Q: Why pseudo-code/algorithm is considered a great way of describing solutions?

This representation is very close to the generalized syntax of a programming language. It provides a clear depth of nested statements and repetition of statements. Pseudocode representation is a bridge between natural language representation and programming language. It is more precise.