Saturday, 10 January 2015

ICT-Memory size calculation





ICT - Algorithms (Selection & Iteration)

Algorithms

An algorithm is a plan, it is a set of step-by-step instructions to solve a particular problem. There are three basic building blocks or constructs to use when designing an algorithm:
They are as under:
  1. sequencing
  2. selection
  3. iteration

Sequencing

Sequencing is a process that provides a solution to your problem in number of steps in a particular sequence.

Selection

Example for selection process includes : How old are you?

An algorithm consists of a set of instructions that are carried out one after an another. Sometimes in any situation, there may be more than one path or steps that can be followed. At that point, a particular decision needs to be made. This point is known as selection.


For example, The following algorithm can be created to determine correct bus charges.
Following are the steps:
  • first of all, ask how old you are ? 
  • if your age is under 13, then pay half charges 
  • otherwise just pay full charges.
The decision comes in step number 2. If you are aged, that is less than 13, only one fare is charged. Otherwise, a different fare is being charged.

IF ...THEN...ELSE

A selection process allows several paths to be included in an algorithm. In algorithms, a selection is usually represented by the instructions that is IF, THEN and ELSE.

  • IF - It represents the question
  • THEN - It points to what to do (or choose option) if the answer to the desired question is true
  • ELSE -  It  points to what to do(or what to choose) if the answer to the desired question is false
Using this method, the fare-related algorithm that we had discussed before now reads like this:

  • ask how old you are 

  • IF you are under 13, THEN pay half fare

  • ELSE pay full fare
If you try the above algorithm using 12 as your age, then the answer to the question at step number 2 will be absolutely true, so  the algorithm tells us that we will pay only half fare.

But if suppose we try the above algorithm using 13 as our age, the answer to the question at step number 2 will be  false,  so the algorithm tells us that we have to pay full fare.

Hence, two different paths are followed according to the answer given to a particular question.

DOWNLOAD