KEMBAR78
Basic Algorithm @PPSC(1) | PPTX
ALGORITHM
Presented by
Amiya Bhusan Bagjadab
Asst. Prof.,
Department of CSE,
Radhakrisna Institute of
Technology and Engineering(RITE)
Contents
 Introduction
 Characteristics of an Algorithm
 Algorithm development process
 Basic Steps For Designing Algorithm
 Some Examples
Introduction
 An algorithm is a sequence of
unambiguous instructions for solving a
problem, i.e., for obtaining a required
output for any legitimate input in a
finite amount of time.
 Algorithm is a step-by-step procedure,
which defines a set of instructions to
be executed in a certain order to get
the desired output.
 Algorithm is any well defined
computational procedure that takes
some value or set of values as input
and produces some value or set of
values as output.
Characteristics of an Algorithm
 Unambiguous − Algorithm should be clear and unambiguous.
Each of its steps (or phases), and their inputs/outputs should be
clear and must lead to only one meaning.
 Input − An algorithm should have 1 or more well-defined inputs.
 Output − An algorithm should have 1 or more well-defined
outputs, and should match the desired output.
 Finiteness − Algorithms must terminate after a finite number of
steps.
 Feasibility − Should be feasible with the available resources.
 Independent − An algorithm should have step-by-step
directions, which should be independent of any programming
code.
Algorithm development process
 Our algorithm development process consists of five
major steps.
Step 1: Obtain a description of the problem.
Step 2: Analyze the problem.
Step 3: Develop a high-level algorithm.
Step 4: Refine the algorithm by adding more detail.
Step 5: Review the algorithm.
Basic Steps For Designing Algorithm
 Step 1 − START
 Step 2 −Take Input Variables
 Step 3 −Develop Logics
 Step 4 − Print the Output
 Step 5 − STOP
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
Find the largest number among
three different numbers
 Step 1: Start
 Step 2: Declare variables a,b and c.
 Step 3: Read variables a,b and c.
 Step 4: If a > b
If a > c
Display a is the largest number.
Else Display c is the largest number.
Else
If b > c
Display b is the largest number.
Else Display c is the greatest number.
Step 5: Stop
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
Check whether a number is a
prime number or not
 Step 1: Start
 Step 2: Declare variables n, i, flag.
 Step 3: Initialize variables
flag ← 1
i ← 2
 Step 4: Read n from the user.
 Step 5: Repeat the steps until i=(n/2)
5.1 If remainder of n÷i equals 0
flag ← 0
Go to step 6
5.2 i ← i+1
Step 6: If flag = 0
Display n is not prime
else
Display n is prime
Step 7: Stop
Basic Algorithm @PPSC(1)

Basic Algorithm @PPSC(1)

  • 1.
    ALGORITHM Presented by Amiya BhusanBagjadab Asst. Prof., Department of CSE, Radhakrisna Institute of Technology and Engineering(RITE)
  • 2.
    Contents  Introduction  Characteristicsof an Algorithm  Algorithm development process  Basic Steps For Designing Algorithm  Some Examples
  • 3.
    Introduction  An algorithmis a sequence of unambiguous instructions for solving a problem, i.e., for obtaining a required output for any legitimate input in a finite amount of time.  Algorithm is a step-by-step procedure, which defines a set of instructions to be executed in a certain order to get the desired output.  Algorithm is any well defined computational procedure that takes some value or set of values as input and produces some value or set of values as output.
  • 4.
    Characteristics of anAlgorithm  Unambiguous − Algorithm should be clear and unambiguous. Each of its steps (or phases), and their inputs/outputs should be clear and must lead to only one meaning.  Input − An algorithm should have 1 or more well-defined inputs.  Output − An algorithm should have 1 or more well-defined outputs, and should match the desired output.  Finiteness − Algorithms must terminate after a finite number of steps.  Feasibility − Should be feasible with the available resources.  Independent − An algorithm should have step-by-step directions, which should be independent of any programming code.
  • 5.
    Algorithm development process Our algorithm development process consists of five major steps. Step 1: Obtain a description of the problem. Step 2: Analyze the problem. Step 3: Develop a high-level algorithm. Step 4: Refine the algorithm by adding more detail. Step 5: Review the algorithm.
  • 6.
    Basic Steps ForDesigning Algorithm  Step 1 − START  Step 2 −Take Input Variables  Step 3 −Develop Logics  Step 4 − Print the Output  Step 5 − STOP
  • 7.
    Design an algorithmto 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
  • 8.
    Find the largestnumber among three different numbers  Step 1: Start  Step 2: Declare variables a,b and c.  Step 3: Read variables a,b and c.  Step 4: If a > b If a > c Display a is the largest number. Else Display c is the largest number. Else If b > c Display b is the largest number. Else Display c is the greatest number. Step 5: Stop
  • 9.
    Factorial of anumber 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
  • 10.
    Check whether anumber is a prime number or not  Step 1: Start  Step 2: Declare variables n, i, flag.  Step 3: Initialize variables flag ← 1 i ← 2  Step 4: Read n from the user.  Step 5: Repeat the steps until i=(n/2) 5.1 If remainder of n÷i equals 0 flag ← 0 Go to step 6 5.2 i ← i+1 Step 6: If flag = 0 Display n is not prime else Display n is prime Step 7: Stop