Home | About | Comments | Lectures | Notice | Registration
Updated : January 20th, 2009
Tell a Friend
You already know something about algorithms. I will prove it to you now. Each day we are faced with challenges which we must overcome. Your solution to each problem is your algorithm for that problem.
This lecture focuses on:
An algorithm is a step by step solution to a problem. It is a set of precisely defined steps guaranteed to arrive at an answer to a problem or a set of problems.
It does not matter what the problem is. As mentioned before, we are faced with problems everyday. Each solution is an algorithm. There are usually different ways to solve a problem. Usually one of the approaches is the most efficient but they are all algorithms.
What if you had an interview for an important job and you wanted to get there on time to give a good first impression. How do you solve that problem?
Your algorithm may look like this :
Mary wanted to bake a cake but did not know how to do it. She borrowed a recepie book from a friend. Selected a special recepie she liked. Purchased the ingredients. Followed the instructions. She then made a tasty cake.
In the above case study Mary had a problem and she found a solution. She developed an algorithm. In fact each recepie in the book is an algorithm. We can think of the baking book as a book of baking algorithms.
What is the relationship between life problems and the problems that a programmer face daily? We go about solving programming problems in very much the same way we solve other problems. If you can solve a real life problem then you can solve a programming problem if you put your mind to it. Many programming problems can be less complicated than most of the challenges we face in life on a regular basis.
Your algorithm may look like this :
Before a programmer writes source code in a high level language he must design a solution. One approach is to first write an algorithm.
Keep these three points in mind
Problem One
Write a program to find the average of any three numbers. These numbers will be input by the user of the program.
Version One
Begin Inupt first number Input second number Input third number calculate sum of the three numbers divide sum by three to calculate average print average End
The above algorithm can be condenced into a simpler version if we use letters for each input value and reduce the processing statements to simple mathematical equations.
Version Two
Begin Input x, y, z sum = x + y + z average = sum / 3 Print average End
There is one INPUT line to get input for three numeric values. There are two PROCESSING lines. The first calculates the sum of the three values input and the second calculates the average of the three input values. Finally there is one OUTPUT statement.
Now Try Problem TwoWrite an algorithm to print the perimeter and the area of a rectangular piece of land.
Given :
perimeter = ( l + b )* 2
area = l * b
Remember
1. Get the required Input data first
2. Secondly perform all Processing ( your calculations )
3. Finally print results or Output
Compare your answer with mine.
The Tutor |
|
Home | About | Comments | Lectures | Notice | Registration