CM304

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 34

DEPARTMENT OF TECHNICAL EDUCATION

ANDHRA PRADESH

Name : Gandi Govinda Naidu


Designation : Head of Computer Engg Section
Branch : Computer Engg
Institute : Govt.Polytechnic for Women,
Bheemunipatnam
Year / Semester : III Semester
Subject : UNIX & C
Subject Code : CM-304
Topic : Understanding Programming
Methodology
Duration : 50 Min
SubTopic : Steps in Algorithm Development
Teaching Aids : PPT, Animations, Photographs

CM304.27 1
Recap

In previous period we have learned about

 Steps in problem solving.

CM304.27 2
Objective

On completion of this period , you would be


able to know
 How to prepare an algorithm for a given
problem
 What are the steps that occur in the solution.

CM304.27 3
Introduction

 The word algorithm comes from the word


Al-Khowarizmi, the Arabian inventor and
means recipe, method, technique or
procedure.
 An algorithm is a step-by-step problem
solving procedure that can be carried out by a
computer.

CM304.27 4
Informal definition of an algorithm
used in a computer

CM304.27 5
The essential properties of an algorithm ?
 It should be simple.
 It should be clear with no ambiguity.
 It should lead to a unique solution of the
problem.
 It should involve a finite number of steps to
arrive at a solution.
 It should have the capability to handle some
unexpected situations which may arise during
the solution of a problem.
CM304.27 6
Steps involved in developing an algorithm:

 Clearly understand the problem statement so


that a proper algorithm can be evolved.
 Study the output to be generated so that the
input can be specified.
 Design the process which will produce the
desired result after taking the input.

CM304.27 7
Steps involved in developing an algorithm:

 Refine the process.


 Test the algorithm by giving the test data and
see if the desired output is generated. If not,
make appropriate changes in the process and
repeat the process.

CM304.27 8
Advantages of algorithms

 It is a step by step solution to a given


problem which is very easy to understand.
 It has got a definite procedure which can be
executed within a set period of time.
 It is easy to first develop an algorithm, then
convert it into a flowchart and then into a
computer program.
CM304.27 9
Advantages of algorithms

 It has got a beginning and an end within


which there are definite procedures to
produce outputs within a specified period of
time.
 It is easy to debug as every step has got its
own logical sequence.
 It is independent of programming
languages.
CM304.27 10
Disadvantages Of Algorithms

 It is time consuming.

 Cumbersome as an algorithm is developed


first which is converted into flowchart and
then into a computer program.

CM304.27 11
Problem Statement

Problem Statement help diagnose the


situation so that your focus is on the problem,
helpful tools at this stage include algorithms
and flowcharts for identifying the expected
steps of a process.

CM304.27 12
Problem Statement

Therefore to solve any problem,


 Collect and analyze information and data.
 Talk with people familiar with the problem.
 If at all possible, view the problem first hand.
 Confirm all findings.

CM304.27 13
Algorithm

The algorithm is part of the blueprint or plan


for the computer program, an algorithm is:
“An effective procedure for solving a class
of problems in a finite number of steps.”

CM304.27 14
Algorithm

Every algorithm should have the following 5


characteristic feature:
1. Input
2. Output
3. Definiteness
4. Effectiveness
5. Termination

CM304.27 15
Algorithm Contd..

To find largest of three numbers


2) Start
3) Read 3 numbers: num1, num2, num3
4) if num1 > num2 then go to step 5
5) if num2 > num3 then
print num2 is largest
else
print num3 is largest
goto step 6
CM304.27 16
Contd..
Algorithm

1) if num1 > num3 then


print num1 is largest
else
print num3 is largest
5) end.

CM304.27 17
Algorithm

Average of two
Average Of Two
Input: Two numbers
3. Add the two numbers
4. Divide the result by 2
5. Return the result by step 2
End

CM304.27 18
Pseudocode & Algorithm

Example 1: Write an algorithm to determine a


student’s final grade and indicate
whether it is pass or fail. The
final grade is calculated as the
average of four marks.

CM304.27 19
Pseudocode & Algorithm

Pseudocode:
 Input a set of marks in four subjects.
 Calculate their average by summing and
dividing by 4
 if average is below 50
Print “FAIL”
else
Print “PASS”
CM304.27 20
Pseudocode & Algorithm

Detailed Algorithm
Step 1: Input M1,M2,M3,M4
Step 2: GRADE ← (M1+M2+M3+M4)/4
Step 3: if (GRADE < 50) then
Print “FAIL”
else
Print “PASS”
endif

CM304.27 21
The Good and the Bad…
Using Algorithms Going without…..

• Avoid problems before • More chance of errors occurring.


they occur.
• Areas of difficulty may be
• Determine areas of unknown until encountered.
difficulty.
• Testing and debugging may be
• Test and debug the logic complicated.
of the process.
• May be able to produce a quicker
• Saves money and time. solution (large risk).
• Divide a task up between • Can suit individuals. Some team
team members efficiently. members may have bigger tasks.
• Easy to project manage. • Time and scope largely unknown.

CM304.27 22
Algorithm in Real Life

Consider the following ….


Problem: Baking a Cake
How to solve:
• Start

• Preheat the oven at 180oC


• Prepare a baking pan
• Beat butter with sugar

CM304.27 23
Algorithm in Real Life

5. Mix them with flour, eggs and essence


vanilla
6. Pour the dough into the baking pan
7. Put the pan into the oven
8 End

CM304.27 24
‘Divide and Conquer’ Strategy in Algorithm

Problem: Prepare a Breakfast

1. Start
2. Prepare a Breakfast
3. End

CM304.27 25
‘Divide and Conquer’ Strategy in Algorithm

1. Start
2. Prepare a Breakfast
2.1 Prepare a tuna sandwich
2.2 Prepare some chips
2.3 Make a cup of coffee
3. End

CM304.27 26
‘Divide and Conquer’ Strategy in Algorithm

1. Start
2. Prepare a Breakfast
2.1 Prepare a tuna sandwich
2.1.1 Take 2 slices of bread
2.1.2 Prepare tuna paste
2.2 Prepare some chips
2.3 Make a cup of coffee
3. End

CM304.27 27
‘Divide and Conquer’ Strategy in Algorithm
1. Start
2. Prepare a Breakfast
2.1 Prepare a tuna sandwich
2.1.1 Take 2 slices of bread
2.1.2 Prepare tuna paste
2.2 Prepare some chips
2.2.1 Cut potatoes into slices
2.2.2 Fry the potatoes
2.3 Make a cup of coffee
3. End
CM304.27 28
‘Divide and Conquer’ Strategy in Algorithm

1. Start
2. Prepare a Breakfast
2.1. Prepare a tuna sandwich
2.1.1 Take 2 slices of bread
2.1.2 Prepare tuna paste
2.2. Prepare some chips
2.2.1 Cut potatoes into slices
2.2.2 Fry the potatoes
2.3. Make a cup of coffee
2.3.1 Boil water
2.3.2 Add water with sugar and coffee
3. End
CM304.27 29
Something to ponder …

What is the connection


between these real life
processes and algorithm?

CM304.27 30
Summary

In this class , you have learned…


 How to prepare a Algorithm for a given
problem
 What are the Steps that occur in the solution.

CM304.27 31
Quiz

1. ... is a step by procedure to solve a


problem.

(a) program
(b) flowchart
(c) algorithm
(d) coding
CM304.27 32
Quiz

1. ... is a step by procedure to solve a


problem.

(a) program
(b) flowchart
(c) algorithm
(d) coding
CM304.27 33
Frequently Asked Questions

3. What is an Algorithm?

2. Explain Algorithm with examples ?

CM304.27 34

You might also like