0% found this document useful (0 votes)
14 views

1.3 Algorithm

The document discusses algorithms and provides examples of algorithms for common problems. It defines an algorithm as a sequence of unambiguous instructions to solve a specific problem. Good algorithms are clear, well-defined, finite, effective, correct, and feasible. Developing an algorithm involves identifying the problem, inputs, outputs, and processing steps. Examples of algorithms provided include adding two numbers, converting temperatures, finding the area and perimeter of a square, and determining the largest of two numbers.

Uploaded by

rajeswarij
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

1.3 Algorithm

The document discusses algorithms and provides examples of algorithms for common problems. It defines an algorithm as a sequence of unambiguous instructions to solve a specific problem. Good algorithms are clear, well-defined, finite, effective, correct, and feasible. Developing an algorithm involves identifying the problem, inputs, outputs, and processing steps. Examples of algorithms provided include adding two numbers, converting temperatures, finding the area and perimeter of a square, and determining the largest of two numbers.

Uploaded by

rajeswarij
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

SUBJECT CODE

TYPE THE SUBJECT NAME HERE

UNIT NO. 1

INTRODUCTION TO PROGRAMMING AND


ALGORITHMS FOR PROBLEM SOLVING

1.3 ALGORITHMS

I I

20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN
C
(Common to CSE & IT)
20PCSPC101
ADVANCED DATA STRUCTURES AND ALGORITHMS

ALGORITHMS

- An algorithm can be defined as “a complete, unambiguous, finite number of


logical steps for solving a specific problem “

● Sequence of instructions to be followed to solve a problem


● Algorithm is generally developed before the actual coding is done
● Independent of underlying programming languages
● It is written in English language statements so that it is to be understood
even by non-programmers.
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)

Characteristics and Properties of Good Algorithms:

● Clear and unambiguous


● Well defined input and output
● Finiteness
● Definiteness
● Effectiveness
● Correctness
● Feasible
● Language Independent
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)

Steps involved in Algorithm Development:

1. The problem that is to be solved by this algorithm


2. Identification of input
3. Identification of output
4. The constraints of the problem that must be considered
5. Identification of the processing steps
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)

Algorithms ---- Examples :

1. Design an algorithm to add two numbers and display the result

Step 1 − START

Step 2 − declare three integers a, b & c

Step 3 − define values of a & b

Step 4 − add values of a & b

Step 5 − store output of step 4 to c

Step 6 − print c

Step 7 − STOP
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)

Algorithms ---- Examples (Contd.,) :

2. Algorithm to convert temperature from Celsius to Fahrenheit

C : temperature in Celsius F : temperature Fahrenheit Algorithm

Step-1 Start

Step-2 Input temperature in Celsius say C

Step-3 F = (9.0/5.0 x C) + 32

Step-4 Display Temperature in Fahrenheit F

Step-5 Stop
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)

Algorithms ---- Examples (Contd.,) :

3. Algorithm to find Area and Perimeter of Square

L : Side Length of Square AREA : Area of Square PERIMETER : Perimeter


of Square

Step-1 Start
Step-2 Input Side Length of Square say L
Step-3 Area = L x L
Step-4 PERIMETER = 4 x L
Step-5 Display AREA, PERIMETER
Step-6 Stop
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)

Algorithms ---- Examples (Contd.,) :

4. Algorithm to find Biggest of Two Numbers

Step 1: Start
Step 2: Declare variables a,b
Step 3: Read variables a,b
Step 4: If a > b
Display a is the largest number.
Else
Display b is the largest number.
Step 5: Stop
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)

Algorithms ---- Examples (Contd.,) :

5. Write an algorithm to find all roots of a quadratic equation ax2+bx+c=0

Step 1: Start
Step 2: Declare variables a, b, c, D, x1, x2, rp and ip;
Step 3: Calculate discriminant
D ← b2-4ac
Step 4: If D ≥ 0
r1 ← (-b+√D)/2a
r2 ← (-b-√D)/2a
Display r1 and r2 as roots.
Else
Calculate real part and imaginary part
rp ← -b/2a
ip ← √(-D)/2a
Display rp+j(ip) and rp-j(ip) as roots
Step 5: Stop
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)

Algorithms ---- Examples (Contd.,) :

6.Write an algorithm to find the factorial of a number entered by the user.

Step 1: Start
Step 2: Declare variables n, factorial and i.
Step 3: Initialize variables
factorial ← 1
i←1
Step 4: Read value of n
Step 5: Repeat the steps until i = n
5.1: factorial ← factorial*i
5.2: i ← i+1
Step 6: Display factorial
Step 7: Stop
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)

Algorithms ---- Examples (Contd.,) :

7. Write an algorithm to find the Fibonacci series till term≤1000

Step 1: Start
Step 2: Declare variables first_term,second_term and temp.
Step 3: Initialize variables first_term ← 0 second_term ← 1
Step 4: Display first_term and second_term
Step 5: Repeat the steps until second_term ≤ 1000
5.1: temp ← second_term
5.2: second_term ← second_term + first_term
5.3: first_term ← temp
5.4: Display second_term
Step 6: Stop
20ESCS101
PROBLEM SOLVING AND PROGRAMMING IN C (Common to CSE & IT)

Thank You

You might also like