Friday, 28 July 2017

Basic Fundamentals Of Programming Algorithms

Basic Fundamentals Of Programming Algorithms:

Introduction to Algorithms:

Algorithms for making things will often be divided into sections;

The parts/components/ingredients (inputs) required to accomplish the task actions/steps/methods (processing) to produce the required outcome (output).

For example to build a model car, the parts (inputs) are needed plus instructions on how to assemble the car (processing) and the result is the car (output).

There are two forms of Algorithm:1 -   Pseudo code2 - Flowchart

Pseudo code:

Pseudocode (which means fake code, because it’s not really programming code) specifies the steps required to accomplish the task.
Pseudocode is a type of structured English that is used to specify an algorithm.
 Pseudocode cannot be compiled nor executed, and there are no real formatting or syntax rules.
Example of Pseudocode:

Ready and open subscriber file
 Get a record
Do while more records
              If current subscriber subscription count is > 3 then
 Output the record
              Get another record

Advantages of Pseudocode:

• Reduced complexity.
• Increased flexibility.
• Ease of understanding. 

Why is Pseudocode Necessary ?

• The programming process is a complicated one.
• You must first understand the program specifications.
• Then you need to organize your thoughts and create the program.
• You must break the main tasks that must be accomplished into smaller ones in order to be able to eventually write fully developed code.
• Writing Pseudocode will save you time later during the construction & testing phase of a program's development. 

How to Write Pseudocode Statements ?

There are six basic operations:
1.  A computer can receive information
Read (information from a file)
Get (information from the keyboard).

2.  A computer can put out information
Write (information to a file)
Display (information to the screen).

3.  A computer can perform arithmetic
Use actual mathematical symbols or the words for the symbols
Add number to total
Total = total + number
+, -, *, /
Calculate, Compute also used.

4.  A computer can assign a value to a piece of data as
3 cases:

i. To give data an initial value

Initialize, Set.

ii. To assign a value as a result of some processing


iii. To keep a piece of information for later use
Save, Store.

5. A computer can compare two piece of information and select one of two alternative actions:

IF condition THEN
                     some action
                     alternative action

6. A computer can repeat a group of actions:

WHILE condition (is true)
some action

FOR a number of times
some action

Data Dictionaries:

• The pseudo code by itself doesn't provide enough information to be able to write program code.
• Data Dictionaries are used to describe the data used in the Pseudo Code.
• The standard data types used in Pseudo Code are Integer, Double, String, Char and Boolean. 

Example 1:
Program Specification:

Write a program that obtains two integer numbers from the user. It will print out the sum of those numbers.


Prompt the user to enter the first integer Prompt the user to enter a second integer Compute the sum of the two user inputs Display an output prompt that explains the answer as the sum Display the result.

Example 2:
Find the average of any three numbers.

We might usually specify the procedure of solving this problem as “add the three numbers and divide by three”. Here, Read (or Ask) and Write (or Say) are implied. However in an algorithm, these steps have to be made explicit. Thus a possible algorithm is:

Step 1    Start
Step 2    Read values of X,Y,Z
Step 3    S=X+Y+Z
Step 4    A=S/3
Step 5    Write value of A
Step 6    Stop

Example 3:
Finding square and cube.

Step 1    Start
Step 2    Read value of N
Step 3    S=N*N
Step 4    C=S*N
Step 5    Write values of S,C
Step 6    Stop

Example 4:
Finding biggest of two numbers.

Step 1    Start
Step 2    Read A,B
Step 3    If A>B, then BIG=A, otherwise BIG=B
Step 4    Write BIG
Step 5    Stop

Example 5:
Calculate pay.

Step 1    Start
Step 2    Input hours
Step 3    Input rate
Step 4    pay=hours*rate
Step 5    Print pay
Step 6   End


• A flowchart is a graphical representation of an algorithm.
• These flowcharts play an important role in programming of a problem and are quite helpful in understanding the logic of complicated and lengthy problems.
• Once the flowchart is drawn, it becomes easy to write the program in any high level language.

A flow chart can therefore be used to:

1-Define and analyze processes
2-Build a step-by-step picture of the process for analysis, discussion, or communication
3-Define, standardize or find are as for improvement in a process.

Flowchart Symbols:

Start and end symbols:

• Represented as lozenges, oval surrounded rectangles.
• Usually containing the word "Start" or "End", or another phrase signaling the start or end of a process, such as "submit enquiry "or" receive product".


• Showing what's called "flow of control" in computer science.
• An arrow coming from one symbol and ending at another symbol.
• Represents that control passes to the symbol the arrow points to.

Processing steps:

• Represented as rectangles.
• Examples: “Add 1 to X"; "replace identified part" ; "save changes" or      similar.


• Represented as a parallelogram.
• Examples: Get X from the user; display X.

Conditional or decision:
• Represented as a diamond.
• These typically contain a Yes/No question or True/False test.

Display Symbol:

• Indicates a process flow step where information is displayed to a person (e. g., PC user, machine operator).

Rules for Flowchart:
1. Every flow chart has a START symbol and a STOP symbol.
2. The flow of sequence is generally from the top of the page to the bottom of the page .This can vary with loops which need to flow back to an entry point.
3. Use arrow-heads on connectors where flow direction may not be obvious.
4. There is only one flow chart per page.

5. A page should have a page number and a title.
6. A flow chart on one page should not break and jump to another page.
7. A flowchart should have no more than around 15 symbols (not including START and STOP).

Advantages of Using Flowcharts:

• Communication: Flowcharts are better way of communicating the logic of a system to all concerned.

• Effective analysis: With the help of flowchart, problem can be analysed in more effective way.

• Proper documentation: Program flowcharts serve as a good program documentation, which is needed for various purposes.

• Efficient Coding: The flow charts act as a guide or blue print during the systems analysis and program development phase.

• Proper Debugging: The flowchart helps in debugging process.

• Efficient Program Maintenance: The maintenance of operating program becomes easy with the help of flowchart. It helps the programmer to put efforts more efficiently on that part.

Basic Control Structures:

1- Sequence
2- Selection
3- Loop

• Steps that execute in sequence are represented by symbols that follow each other top to bottom or left to right.
• Top to bottom is the standard.

• Once the condition is evaluated, the control flows in to one of two paths.
• Once the conditional execution is finished, the flows rejoin before leaving the structure.
• Either the processing repeats or the control leaves the structure.
• Notice that the return line joins the entry line be fore the question.



Input: two numbers x and y
Output: the average of x and y
1. input x
2. input y
3. sum = x+y
4. output sum


Try it yourself.
If you have any problem you can tell me on comment box i will help you.

Viral Programs

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation.


  1. Nice and helpful article thanks to share us keep it up.

  2. Hey
    such an informative article thanks for sharing with us
    keep it up for the good work

  3. Hi viralprograms
    Really very informative article. I like the way you make the comparison with chocolate. Thanks for sharing with us.

    Keep up for the good work.


  4. Hi
    Really very informative article. I like the way you make the comparison with chocolate. Thanks for sharing with us.

    Keep up for the good work.