SlideShare a Scribd company logo
Introduction to Computer Science and Engineering
by :Nandini Sidana
LOGIC DEVELOPMENT AND ALGORITHM
Various Techniques to solve a problem
Introduction
 A computer is a very powerful and versatile machine, yet it has no
intelligence or thinking power.
 This places responsibility on the user to instruct the computer in a correct
and precise manner, so that the machine is able to perform the required
job in a proper way.
 In order to instruct a computer correctly:
● the user must have clear understanding of the problem to be solved
● he should be able to develop a method, in the form of series of
sequential steps, to solve it
Procedure (Steps Involved in Problem Solving)
In order to solve a problem by the computer, one has to
pass though certain stages or steps. They are
 Step 1: Understanding the problem
Here we try to understand the problem to be solved in
totally. Before with the next stage or step, we should be
absolutely sure about the objectives of the given problem.
Step 2: . Analysing the problem
After understanding thoroughly the problem to be solved, we look different ways
of solving the problem and evaluate each of these methods. The idea here is to
search an appropriate solution to the problem under consideration. The end result
of this stage is a broad overview of the sequence of operations that are to be carries
out to solve the given problem.
Step 3: Developing the solution
Here the overview of the sequence of operations that was the result of analysis
stage is expanded to form a detailed step by step solution to the problem under
consideration.
Step 4: Coding and Implementation
The last stage of the problem solving is the conversion of the detailed
sequence of operations in to a language that the computer can
understand. Here each step is converted to its equivalent instruction
or instructions in the computer language that has been chosen
for the implantation.
An algorithm is a plan for solving a problem.
 Every problem solution starts with a plan and that plan is called an algorithm.
There are many ways to write an algorithm:
• Formal
• Informal
• Mathematical or
• Graphical
The form is not particularly important as long as it provides a good way to describe
and check the logic of the plan.
A set of sequential steps usually written in Ordinary
Language to solve a given problem is called Algorithm.
 It may be possible to solve to problem in more than one ways,
resulting in more than one algorithm.
 The choice of various algorithms depends on the factors like:
reliability
accuracy
easy to modify and
time requirement to execute it
 The algorithm which will need the least time when executed is
considered the best.
An algorithm can be defined as “a complete,
unambiguous, finite number of logical steps for solving a
specific problem “
Steps involved in algorithm development :
• Identification of input: For an algorithm, there are quantities to be
supplied called input. The input is to be identified first for any specified problem.
• Identification of output: From an algorithm, at least one quantity is produced,
called for any specified problem.
• Identification of processing operations : All the calculations to be performed
in order to lead to output from the input are to be identified in an orderly manner.
• Processing Definiteness : The instructions composing the algorithm
must be clear and there should not be any ambiguity in them.
• Processing Finiteness : If we go through the algorithm, then for all
cases, the algorithm should terminate after a finite number of steps.
• Possessing Effectiveness : The instructions in the algorithm must
be sufficiently basic and in practice they can be carries out easily.
Properties of Algorithm:
 Finiteness: An algorithm must terminate in a finite number of steps
 Definiteness: Each step of the algorithm must be precise and
definite
 Effectiveness: Each step must be effective, in the sense that it
should be easily convertible into program statement and can be
performed exactly in a finite amount of time.
 Generality: The algorithm must be complete in itself so that it can
be used to solve problems of a specific type for any input data.
 Input/output: Each algorithm must take zero, one or more
quantities as input data produce one or more output values
Try it out !!!!
Examples:
 Find the average of three numbers.
 Write an algorithm to calculate the simple interest using the formula. Simple interest = P*N* R/100.
Where P is principle Amount, N is the number of years and R is the rate of interest.
 Write an algorithm to find the area of the triangle.
Let b, c be the sides of the triangle ABC and A the included angle between the given sides.
 Write an algorithm to find the largest of three numbers X, Y,Z
 Write an algorithm which will test whether a given integer value is prime or not.
 Write algorithm to find the factorial of a given number N
 Write an algorithm to find sum of given data values until negative value is entered.
 Write an algorithm to calculate the perimeter and area of rectangle. Given its length and width
❑ Write algorithm to
find the factorial of
a given number N
STEP 1: PROD =1
STEP 2: I = 0
STEP 3: READ N
STEP 4: WHILE I < N DO
4.1 I = I + 1
4.2. PROD = PROD* I
STEP 5: WRITE “FACTORIAL OF”, N,
“IS”, PROD
STEP 6: END.
❑ Find the average
of three numbers. STEP 1: READ THE NUMBERS A, B, C
STEP 2 : COMPUTE THE SUM OF A, B AND C
STEP 3 : DIVIDE THE SUM BY 3
STEP 4 : STORE THE RESULT IN VARIABLE D
STEP 5 : PRINT THE VALUE OF D
STEP 6 : END OF THE PROGRAM
❑ Write an algorithm to
calculate the simple
interest using the
formula. Simple
interest = P*N* R/100.
Where P is principle
Amount, N is the
number of years and
R is the rate of
interest.
STEP 1: READ THE THREE INPUT QUANTITIES’
P, N AND R.
STEP 2 : CALCULATE SIMPLE INTEREST AS
SIMPLE INTEREST = P* N* R/100
STEP 3: PRINT SIMPLE INTEREST.
STEP 4: STOP.
❑ Write an algorithm to
find the area of the
triangle.
Let b, c be the sides of
the triangle ABC and A
the included angle
between the given
sides.
STEP 1: INPUT THE GIVEN ELEMENTS OF THE
TRIANGLE NAMELY SIDES B, C AND
ANGLE BETWEEN THE SIDES A.
STEP 2: AREA = (1/2) *B*C* SIN A
STEP 3: OUTPUT THE AREA
STEP 4: STOP.
❑ Write an algorithm
to find the largest
of three numbers
X, Y,Z
STEP 1: READ THE NUMBERS X,Y,Z.
STEP 2: IF (X > Y) BIG = X ELSE BIG = Y
STEP 3 : IF (BIG < Z)
STEP 4: BIG = Z
STEP 5: PRINT THE LARGEST NUMBER I.E. BIG
STEP 6: STOP.
❑ Write an algorithm
which will test whether
a given integer value
is prime or not.
STEP 1: M=2
STEP 2: READ N
STEP 3: MAX=SQRT (N)
STEP 4: WHILE M < = MAX DO
4.1 IF (M* (N/M) = N
4.1.1 THEN
4.1.1.1 GO TO STEP 7
4.2. M = M + 1
STEP 5: WRITE “NUMBER IS PRIME”
STEP 6: GO TO STEP 8
STEP 7: WRITE “NUMBER IS NOT A
PRIME”
STEP 8: END.
❑ Write an algorithm
to find sum of
given data values
until negative
value is entered.
STEP 1: SUM = 0
STEP 2: I = 0
STEP 3: READ NEW VALUE
STEP 4: WHILE NEW VALUE < = 0 DO
4.1 SUM = SUM + NEW VALUE
4.2 1 = I + 1
4.3 READ NEW VALUE
STEP 5: WRITE “SUM OF”, I, “DATA
VALUE IS, “SUM
STEP 6: END
❑ Write an algorithm
to calculate the
perimeter and
area of rectangle.
Given its length
and width
STEP 1: READ LENGTH OF THE
RECTANGLE.
STEP 2: READ WIDTH OF THE
RECTANGLE.
STEP 3: CALCULATE PERIMETER OF THE
RECTANGLE USING THE FORMULA
PERIMETER = 2* (LENGTH + WIDTH)
STEP 4: CALCULATE AREA OF THE
RECTANGLE USING THE FORMULA
AREA = LENGTH *WIDTH. 256
COMPUTER SCIENCE AND
ENGINEERING
STEP 5: PRINT PERIMETER.
STEP 6: PRINT AREA.
STEP 7: STOP.
Ways to specify an algorithm
‘FLOWCHARTS’ AND ‘PSEUDO CODES’
Flowcharts
A flowchart is visual or graphical representation of an algorithm.
Introduction
 A flow chart is a step by step diagrammatic representation of
the logic paths to solve a given problem.
 The flowcharts are pictorial representation of the methods to b
used to solve a given problem and help a great deal to analyze
the problem and plan its solution in a systematic and orderly
manner.
 A flowchart when translated in to a proper computer language,
results in a complete program.
Advantages of Flowcharts:
 The flowchart shows the logic of a problem displayed in pictorial fashion
which felicitates easier checking of an algorithm.
 The Flowchart is good means of communication to other users. It is also a
compact means of recording an algorithm solution to a problem.
 The flowchart allows the problem solver to break the problem into parts.
These parts can be connected to make master chart.
 The flowchart is a permanent record of the solution which can be consulted
at a later time.
Difference between Algorithm and Flowchart
Algorithm
 A method of representing the step-by-
step logical procedure for solving a
problem
 It contains step-by-step English
descriptions, each step representing a
particular operation leading to
solution of problem
 These are particularly useful for small
problems
 For complex programs, algorithms
prove to be Inadequate
Flowchart
 Flowchart is diagrammatic
representation of an algorithm. It is
constructed using different types of
boxes and symbols.
 The flowchart employs a series of blocks
and arrows, each of which represents a
particular step in an algorithm
 These are useful for detailed
representations of complicated programs
 For complex programs, Flowcharts prove
to be adequate
Symbols used in flowcharts:
The symbols that we make use while drawing flowcharts as given below are as per conventions
followed by International Standard Organization (ISO).
 Oval: Rectangle with rounded sides is used to indicate either START/ STOP of the program.
 Input and output indicators: Parallelograms are used to represent input and output
operations. Statements like INPUT, READ and PRINT are represented in these Parallelograms.
Process Indicators: - Rectangle is used to indicate any set of processing operation
such as for storing arithmetic operations.
Decision Makers: The diamond is used for indicating the step of decision making and therefore
known as decision box. Decision boxes are used to test the conditions or ask questions and
depending upon the answers, the appropriate actions are taken by the computer.
The decision box symbol is
Flow Lines: Flow lines indicate the direction being followed in the flowchart. In a Flowchart,
every line must have an arrow on it to indicate the direction. The arrows may be in any direction
On- Page connectors: Circles are used to join the different parts of a flowchart and
these circles are called on-page connectors. The uses of these connectors give a neat
shape to the flowcharts. Ina complicated problems, a flowchart may run in to several pages.
The parts of the flowchart on different pages are to be joined with each other.
The parts to be joined are indicated by the circle.
Off-page connectors: This connector represents a break in the path of flowchart which is too large
to fit on a single page. It is similar to on-page connector. The connector symbol marks where the
algorithm ends on the first page and where it continues on the second
Example: Draw a flowchart for adding the
integers from 1 to 100 and to print the sum.
Start
Sum=0
N=1
Stop
Is N>100?
Print Sum
Sum=Sum+N
N=N+1
Yes
No
Try it yourself:
 Draw the Flowchart to find Roots of Quadratic equation a𝑥2
+ b𝑥 + c = 0.
The coefficients a, b, c are the input data.
 Draw a flowchart to find out the biggest of the three unequal positive
numbers.
 Draw a flowchart to find the factorial of given positive integer N.
 ABC company plans to give a 6% year-end bonus to each of its
employees earning $6,000 or more per month , and a fixed $250/- - bonus
to the remaining employees. Draw a flowchart for calculating the bonus
for an employee
Pseudo Codes
❑ The Pseudo code is neither an algorithm nor a program.
❑ It is an abstract form of a program. It consists of English like
statements which perform the specific operations.
❑ It is defined for an algorithm.
❑ It does not use any graphical representation.
❑ In pseudo code, the program is represented in terms of
words and phrases, but the syntax of program is not strictly
followed.
Advantages of Pseudo Code:
 Easy to read
 Easy to understand
 Easy to modify
Example: Write a pseudo code to perform
the basic arithmetic operations.
 Read n1, n2
 Sum = n1 + n2
 Diff = n1 – n2
 Mult = n1 * n2
 Quot = n1/n2
 Print sum, diff, mult, quot
 End.
Good Luck ☺
Ad

More Related Content

What's hot (20)

Lecture 5 - Structured Programming Language
Lecture 5 - Structured Programming Language Lecture 5 - Structured Programming Language
Lecture 5 - Structured Programming Language
Md. Imran Hossain Showrov
 
Algorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to Algorithms
Mohamed Loey
 
Variables in C++, data types in c++
Variables in C++, data types in c++Variables in C++, data types in c++
Variables in C++, data types in c++
Neeru Mittal
 
Introduction to Compiler design
Introduction to Compiler design Introduction to Compiler design
Introduction to Compiler design
Dr. C.V. Suresh Babu
 
Constant, variables, data types
Constant, variables, data typesConstant, variables, data types
Constant, variables, data types
Pratik Devmurari
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
programming9
 
Introduction to Pseudocode
Introduction to PseudocodeIntroduction to Pseudocode
Introduction to Pseudocode
Damian T. Gordon
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
Rabin BK
 
Operators
OperatorsOperators
Operators
Krishna Kumar Pankaj
 
Binary Arithmetic
Binary ArithmeticBinary Arithmetic
Binary Arithmetic
gavhays
 
Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis
Dr. Pankaj Agarwal
 
Pseudo code
Pseudo codePseudo code
Pseudo code
Arindam Ghosh
 
Basics of c++ Programming Language
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics of c++ Programming Language
Ahmad Idrees
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
Mir Majid
 
Introduction to flowchart
Introduction to flowchartIntroduction to flowchart
Introduction to flowchart
Jordan Delacruz
 
Constants and variables in c programming
Constants and variables in c programmingConstants and variables in c programming
Constants and variables in c programming
Chitrank Dixit
 
History of Programming Language
History of Programming LanguageHistory of Programming Language
History of Programming Language
tahria123
 
EASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdf
EASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdfEASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdf
EASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdf
sudhakargeruganti
 
Unit 1-problem solving with algorithm
Unit 1-problem solving with algorithmUnit 1-problem solving with algorithm
Unit 1-problem solving with algorithm
rajkumar1631010038
 
Algorithm and pseudo codes
Algorithm and pseudo codesAlgorithm and pseudo codes
Algorithm and pseudo codes
hermiraguilar
 
Lecture 5 - Structured Programming Language
Lecture 5 - Structured Programming Language Lecture 5 - Structured Programming Language
Lecture 5 - Structured Programming Language
Md. Imran Hossain Showrov
 
Algorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to Algorithms
Mohamed Loey
 
Variables in C++, data types in c++
Variables in C++, data types in c++Variables in C++, data types in c++
Variables in C++, data types in c++
Neeru Mittal
 
Constant, variables, data types
Constant, variables, data typesConstant, variables, data types
Constant, variables, data types
Pratik Devmurari
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
programming9
 
Introduction to Pseudocode
Introduction to PseudocodeIntroduction to Pseudocode
Introduction to Pseudocode
Damian T. Gordon
 
Algorithm and flowchart
Algorithm and flowchartAlgorithm and flowchart
Algorithm and flowchart
Rabin BK
 
Binary Arithmetic
Binary ArithmeticBinary Arithmetic
Binary Arithmetic
gavhays
 
Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis Introduction to Algorithms Complexity Analysis
Introduction to Algorithms Complexity Analysis
Dr. Pankaj Agarwal
 
Basics of c++ Programming Language
Basics of c++ Programming LanguageBasics of c++ Programming Language
Basics of c++ Programming Language
Ahmad Idrees
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
Mir Majid
 
Introduction to flowchart
Introduction to flowchartIntroduction to flowchart
Introduction to flowchart
Jordan Delacruz
 
Constants and variables in c programming
Constants and variables in c programmingConstants and variables in c programming
Constants and variables in c programming
Chitrank Dixit
 
History of Programming Language
History of Programming LanguageHistory of Programming Language
History of Programming Language
tahria123
 
EASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdf
EASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdfEASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdf
EASY UNDERSTANDING OF POINTERS IN C LANGUAGE.pdf
sudhakargeruganti
 
Unit 1-problem solving with algorithm
Unit 1-problem solving with algorithmUnit 1-problem solving with algorithm
Unit 1-problem solving with algorithm
rajkumar1631010038
 
Algorithm and pseudo codes
Algorithm and pseudo codesAlgorithm and pseudo codes
Algorithm and pseudo codes
hermiraguilar
 

Similar to Logic Development and Algorithm. (20)

Algorithm for computational problematic sit
Algorithm for computational problematic sitAlgorithm for computational problematic sit
Algorithm for computational problematic sit
Saurabh846965
 
Algorithm types performance steps working
Algorithm types performance steps workingAlgorithm types performance steps working
Algorithm types performance steps working
Saurabh846965
 
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffdPROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
dinesh620610
 
Introduction to Problem Solving Techniques
Introduction to Problem Solving TechniquesIntroduction to Problem Solving Techniques
Introduction to Problem Solving Techniques
Sitamarhi Institute of Technology
 
Problem solving techniques in c language
Problem solving techniques in c languageProblem solving techniques in c language
Problem solving techniques in c language
John Bruslin
 
Problem solving methodology
Problem solving methodologyProblem solving methodology
Problem solving methodology
Prof. Dr. K. Adisesha
 
Basics of Algorithm Unit 1 part 1 algorithm
Basics of Algorithm Unit 1 part 1  algorithmBasics of Algorithm Unit 1 part 1  algorithm
Basics of Algorithm Unit 1 part 1 algorithm
JIMS LAJPAT NAGAR
 
C LANGUAGE-FLOWCHARTS,PSEUDOCODE,ALGORITHMS APPROCHES
C LANGUAGE-FLOWCHARTS,PSEUDOCODE,ALGORITHMS APPROCHESC LANGUAGE-FLOWCHARTS,PSEUDOCODE,ALGORITHMS APPROCHES
C LANGUAGE-FLOWCHARTS,PSEUDOCODE,ALGORITHMS APPROCHES
HarshJha34
 
01 Introduction to analysis of Algorithms.pptx
01 Introduction to analysis of Algorithms.pptx01 Introduction to analysis of Algorithms.pptx
01 Introduction to analysis of Algorithms.pptx
ssuser586772
 
Chp-1 DAA (2).pptx design analysis and algoritham presentation
Chp-1 DAA (2).pptx design analysis and algoritham presentationChp-1 DAA (2).pptx design analysis and algoritham presentation
Chp-1 DAA (2).pptx design analysis and algoritham presentation
vaishnavbhavna17
 
Flowcharting and Algorithm
Flowcharting and Algorithm Flowcharting and Algorithm
Flowcharting and Algorithm
Zeinna Belle Desamito
 
Algorithms.pdf
Algorithms.pdfAlgorithms.pdf
Algorithms.pdf
OluwafolakeOjo
 
Module 1 python.pptx
Module 1 python.pptxModule 1 python.pptx
Module 1 python.pptx
AnuragJoshi813963
 
Chap6
Chap6Chap6
Chap6
artipradhan
 
UNIT-2-PPTS-DAA.ppt
UNIT-2-PPTS-DAA.pptUNIT-2-PPTS-DAA.ppt
UNIT-2-PPTS-DAA.ppt
GovindUpadhyay25
 
UNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.pptUNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.ppt
racha49
 
UNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.pptUNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.ppt
SamridhiGulati4
 
Introduction to Design Algorithm And Analysis.ppt
Introduction to Design Algorithm And Analysis.pptIntroduction to Design Algorithm And Analysis.ppt
Introduction to Design Algorithm And Analysis.ppt
BhargaviDalal4
 
Algorithm.pdf
Algorithm.pdfAlgorithm.pdf
Algorithm.pdf
MIT,Imphal
 
UNIT 1- Design Analysis of algorithms and its working
UNIT 1- Design Analysis of algorithms and its workingUNIT 1- Design Analysis of algorithms and its working
UNIT 1- Design Analysis of algorithms and its working
Bobby Pra A
 
Algorithm for computational problematic sit
Algorithm for computational problematic sitAlgorithm for computational problematic sit
Algorithm for computational problematic sit
Saurabh846965
 
Algorithm types performance steps working
Algorithm types performance steps workingAlgorithm types performance steps working
Algorithm types performance steps working
Saurabh846965
 
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffdPROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
dinesh620610
 
Problem solving techniques in c language
Problem solving techniques in c languageProblem solving techniques in c language
Problem solving techniques in c language
John Bruslin
 
Basics of Algorithm Unit 1 part 1 algorithm
Basics of Algorithm Unit 1 part 1  algorithmBasics of Algorithm Unit 1 part 1  algorithm
Basics of Algorithm Unit 1 part 1 algorithm
JIMS LAJPAT NAGAR
 
C LANGUAGE-FLOWCHARTS,PSEUDOCODE,ALGORITHMS APPROCHES
C LANGUAGE-FLOWCHARTS,PSEUDOCODE,ALGORITHMS APPROCHESC LANGUAGE-FLOWCHARTS,PSEUDOCODE,ALGORITHMS APPROCHES
C LANGUAGE-FLOWCHARTS,PSEUDOCODE,ALGORITHMS APPROCHES
HarshJha34
 
01 Introduction to analysis of Algorithms.pptx
01 Introduction to analysis of Algorithms.pptx01 Introduction to analysis of Algorithms.pptx
01 Introduction to analysis of Algorithms.pptx
ssuser586772
 
Chp-1 DAA (2).pptx design analysis and algoritham presentation
Chp-1 DAA (2).pptx design analysis and algoritham presentationChp-1 DAA (2).pptx design analysis and algoritham presentation
Chp-1 DAA (2).pptx design analysis and algoritham presentation
vaishnavbhavna17
 
UNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.pptUNIT-1-PPTS-DAA.ppt
UNIT-1-PPTS-DAA.ppt
racha49
 
Introduction to Design Algorithm And Analysis.ppt
Introduction to Design Algorithm And Analysis.pptIntroduction to Design Algorithm And Analysis.ppt
Introduction to Design Algorithm And Analysis.ppt
BhargaviDalal4
 
UNIT 1- Design Analysis of algorithms and its working
UNIT 1- Design Analysis of algorithms and its workingUNIT 1- Design Analysis of algorithms and its working
UNIT 1- Design Analysis of algorithms and its working
Bobby Pra A
 
Ad

Recently uploaded (20)

introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
Mathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdfMathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdf
TalhaShahid49
 
New Microsoft PowerPoint Presentation.pdf
New Microsoft PowerPoint Presentation.pdfNew Microsoft PowerPoint Presentation.pdf
New Microsoft PowerPoint Presentation.pdf
mohamedezzat18803
 
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITYADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ijscai
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Journal of Soft Computing in Civil Engineering
 
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdfMAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
ssuser562df4
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
Resistance measurement and cfd test on darpa subboff model
Resistance measurement and cfd test on darpa subboff modelResistance measurement and cfd test on darpa subboff model
Resistance measurement and cfd test on darpa subboff model
INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
Metal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistryMetal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistry
mee23nu
 
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxbMain cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
SunilSingh610661
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
Artificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptxArtificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptx
DrMarwaElsherif
 
lecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIH
lecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIHlecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIH
lecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIH
Abodahab
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)
Vəhid Gəruslu
 
How to use nRF24L01 module with Arduino
How to use nRF24L01 module with ArduinoHow to use nRF24L01 module with Arduino
How to use nRF24L01 module with Arduino
CircuitDigest
 
introduction to machine learining for beginers
introduction to machine learining for beginersintroduction to machine learining for beginers
introduction to machine learining for beginers
JoydebSheet
 
Mathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdfMathematical foundation machine learning.pdf
Mathematical foundation machine learning.pdf
TalhaShahid49
 
New Microsoft PowerPoint Presentation.pdf
New Microsoft PowerPoint Presentation.pdfNew Microsoft PowerPoint Presentation.pdf
New Microsoft PowerPoint Presentation.pdf
mohamedezzat18803
 
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITYADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ijscai
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdfRICS Membership-(The Royal Institution of Chartered Surveyors).pdf
RICS Membership-(The Royal Institution of Chartered Surveyors).pdf
MohamedAbdelkader115
 
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdfMAQUINARIA MINAS CEMA 6th Edition (1).pdf
MAQUINARIA MINAS CEMA 6th Edition (1).pdf
ssuser562df4
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
Introduction to FLUID MECHANICS & KINEMATICS
Introduction to FLUID MECHANICS &  KINEMATICSIntroduction to FLUID MECHANICS &  KINEMATICS
Introduction to FLUID MECHANICS & KINEMATICS
narayanaswamygdas
 
Metal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistryMetal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistry
mee23nu
 
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxbMain cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
Main cotrol jdbjbdcnxbjbjzjjjcjicbjxbcjcxbjcxb
SunilSingh610661
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
Degree_of_Automation.pdf for Instrumentation and industrial specialist
Degree_of_Automation.pdf for  Instrumentation  and industrial specialistDegree_of_Automation.pdf for  Instrumentation  and industrial specialist
Degree_of_Automation.pdf for Instrumentation and industrial specialist
shreyabhosale19
 
Artificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptxArtificial Intelligence introduction.pptx
Artificial Intelligence introduction.pptx
DrMarwaElsherif
 
lecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIH
lecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIHlecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIH
lecture5.pptxJHKGJFHDGTFGYIUOIUIPIOIPUOHIYGUYFGIH
Abodahab
 
Compiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptxCompiler Design_Lexical Analysis phase.pptx
Compiler Design_Lexical Analysis phase.pptx
RushaliDeshmukh2
 
AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)AI-assisted Software Testing (3-hours tutorial)
AI-assisted Software Testing (3-hours tutorial)
Vəhid Gəruslu
 
How to use nRF24L01 module with Arduino
How to use nRF24L01 module with ArduinoHow to use nRF24L01 module with Arduino
How to use nRF24L01 module with Arduino
CircuitDigest
 
Ad

Logic Development and Algorithm.

  • 1. Introduction to Computer Science and Engineering by :Nandini Sidana LOGIC DEVELOPMENT AND ALGORITHM
  • 2. Various Techniques to solve a problem
  • 3. Introduction  A computer is a very powerful and versatile machine, yet it has no intelligence or thinking power.  This places responsibility on the user to instruct the computer in a correct and precise manner, so that the machine is able to perform the required job in a proper way.  In order to instruct a computer correctly: ● the user must have clear understanding of the problem to be solved ● he should be able to develop a method, in the form of series of sequential steps, to solve it
  • 4. Procedure (Steps Involved in Problem Solving) In order to solve a problem by the computer, one has to pass though certain stages or steps. They are  Step 1: Understanding the problem Here we try to understand the problem to be solved in totally. Before with the next stage or step, we should be absolutely sure about the objectives of the given problem.
  • 5. Step 2: . Analysing the problem After understanding thoroughly the problem to be solved, we look different ways of solving the problem and evaluate each of these methods. The idea here is to search an appropriate solution to the problem under consideration. The end result of this stage is a broad overview of the sequence of operations that are to be carries out to solve the given problem. Step 3: Developing the solution Here the overview of the sequence of operations that was the result of analysis stage is expanded to form a detailed step by step solution to the problem under consideration.
  • 6. Step 4: Coding and Implementation The last stage of the problem solving is the conversion of the detailed sequence of operations in to a language that the computer can understand. Here each step is converted to its equivalent instruction or instructions in the computer language that has been chosen for the implantation.
  • 7. An algorithm is a plan for solving a problem.  Every problem solution starts with a plan and that plan is called an algorithm. There are many ways to write an algorithm: • Formal • Informal • Mathematical or • Graphical The form is not particularly important as long as it provides a good way to describe and check the logic of the plan.
  • 8. A set of sequential steps usually written in Ordinary Language to solve a given problem is called Algorithm.  It may be possible to solve to problem in more than one ways, resulting in more than one algorithm.  The choice of various algorithms depends on the factors like: reliability accuracy easy to modify and time requirement to execute it  The algorithm which will need the least time when executed is considered the best.
  • 9. An algorithm can be defined as “a complete, unambiguous, finite number of logical steps for solving a specific problem “ Steps involved in algorithm development : • Identification of input: For an algorithm, there are quantities to be supplied called input. The input is to be identified first for any specified problem. • Identification of output: From an algorithm, at least one quantity is produced, called for any specified problem. • Identification of processing operations : All the calculations to be performed in order to lead to output from the input are to be identified in an orderly manner.
  • 10. • Processing Definiteness : The instructions composing the algorithm must be clear and there should not be any ambiguity in them. • Processing Finiteness : If we go through the algorithm, then for all cases, the algorithm should terminate after a finite number of steps. • Possessing Effectiveness : The instructions in the algorithm must be sufficiently basic and in practice they can be carries out easily.
  • 11. Properties of Algorithm:  Finiteness: An algorithm must terminate in a finite number of steps  Definiteness: Each step of the algorithm must be precise and definite  Effectiveness: Each step must be effective, in the sense that it should be easily convertible into program statement and can be performed exactly in a finite amount of time.  Generality: The algorithm must be complete in itself so that it can be used to solve problems of a specific type for any input data.  Input/output: Each algorithm must take zero, one or more quantities as input data produce one or more output values
  • 12. Try it out !!!! Examples:  Find the average of three numbers.  Write an algorithm to calculate the simple interest using the formula. Simple interest = P*N* R/100. Where P is principle Amount, N is the number of years and R is the rate of interest.  Write an algorithm to find the area of the triangle. Let b, c be the sides of the triangle ABC and A the included angle between the given sides.  Write an algorithm to find the largest of three numbers X, Y,Z  Write an algorithm which will test whether a given integer value is prime or not.  Write algorithm to find the factorial of a given number N  Write an algorithm to find sum of given data values until negative value is entered.  Write an algorithm to calculate the perimeter and area of rectangle. Given its length and width
  • 13. ❑ Write algorithm to find the factorial of a given number N STEP 1: PROD =1 STEP 2: I = 0 STEP 3: READ N STEP 4: WHILE I < N DO 4.1 I = I + 1 4.2. PROD = PROD* I STEP 5: WRITE “FACTORIAL OF”, N, “IS”, PROD STEP 6: END.
  • 14. ❑ Find the average of three numbers. STEP 1: READ THE NUMBERS A, B, C STEP 2 : COMPUTE THE SUM OF A, B AND C STEP 3 : DIVIDE THE SUM BY 3 STEP 4 : STORE THE RESULT IN VARIABLE D STEP 5 : PRINT THE VALUE OF D STEP 6 : END OF THE PROGRAM
  • 15. ❑ Write an algorithm to calculate the simple interest using the formula. Simple interest = P*N* R/100. Where P is principle Amount, N is the number of years and R is the rate of interest. STEP 1: READ THE THREE INPUT QUANTITIES’ P, N AND R. STEP 2 : CALCULATE SIMPLE INTEREST AS SIMPLE INTEREST = P* N* R/100 STEP 3: PRINT SIMPLE INTEREST. STEP 4: STOP.
  • 16. ❑ Write an algorithm to find the area of the triangle. Let b, c be the sides of the triangle ABC and A the included angle between the given sides. STEP 1: INPUT THE GIVEN ELEMENTS OF THE TRIANGLE NAMELY SIDES B, C AND ANGLE BETWEEN THE SIDES A. STEP 2: AREA = (1/2) *B*C* SIN A STEP 3: OUTPUT THE AREA STEP 4: STOP.
  • 17. ❑ Write an algorithm to find the largest of three numbers X, Y,Z STEP 1: READ THE NUMBERS X,Y,Z. STEP 2: IF (X > Y) BIG = X ELSE BIG = Y STEP 3 : IF (BIG < Z) STEP 4: BIG = Z STEP 5: PRINT THE LARGEST NUMBER I.E. BIG STEP 6: STOP.
  • 18. ❑ Write an algorithm which will test whether a given integer value is prime or not. STEP 1: M=2 STEP 2: READ N STEP 3: MAX=SQRT (N) STEP 4: WHILE M < = MAX DO 4.1 IF (M* (N/M) = N 4.1.1 THEN 4.1.1.1 GO TO STEP 7 4.2. M = M + 1 STEP 5: WRITE “NUMBER IS PRIME” STEP 6: GO TO STEP 8 STEP 7: WRITE “NUMBER IS NOT A PRIME” STEP 8: END.
  • 19. ❑ Write an algorithm to find sum of given data values until negative value is entered. STEP 1: SUM = 0 STEP 2: I = 0 STEP 3: READ NEW VALUE STEP 4: WHILE NEW VALUE < = 0 DO 4.1 SUM = SUM + NEW VALUE 4.2 1 = I + 1 4.3 READ NEW VALUE STEP 5: WRITE “SUM OF”, I, “DATA VALUE IS, “SUM STEP 6: END
  • 20. ❑ Write an algorithm to calculate the perimeter and area of rectangle. Given its length and width STEP 1: READ LENGTH OF THE RECTANGLE. STEP 2: READ WIDTH OF THE RECTANGLE. STEP 3: CALCULATE PERIMETER OF THE RECTANGLE USING THE FORMULA PERIMETER = 2* (LENGTH + WIDTH) STEP 4: CALCULATE AREA OF THE RECTANGLE USING THE FORMULA AREA = LENGTH *WIDTH. 256 COMPUTER SCIENCE AND ENGINEERING STEP 5: PRINT PERIMETER. STEP 6: PRINT AREA. STEP 7: STOP.
  • 21. Ways to specify an algorithm ‘FLOWCHARTS’ AND ‘PSEUDO CODES’
  • 22. Flowcharts A flowchart is visual or graphical representation of an algorithm.
  • 23. Introduction  A flow chart is a step by step diagrammatic representation of the logic paths to solve a given problem.  The flowcharts are pictorial representation of the methods to b used to solve a given problem and help a great deal to analyze the problem and plan its solution in a systematic and orderly manner.  A flowchart when translated in to a proper computer language, results in a complete program.
  • 24. Advantages of Flowcharts:  The flowchart shows the logic of a problem displayed in pictorial fashion which felicitates easier checking of an algorithm.  The Flowchart is good means of communication to other users. It is also a compact means of recording an algorithm solution to a problem.  The flowchart allows the problem solver to break the problem into parts. These parts can be connected to make master chart.  The flowchart is a permanent record of the solution which can be consulted at a later time.
  • 25. Difference between Algorithm and Flowchart Algorithm  A method of representing the step-by- step logical procedure for solving a problem  It contains step-by-step English descriptions, each step representing a particular operation leading to solution of problem  These are particularly useful for small problems  For complex programs, algorithms prove to be Inadequate Flowchart  Flowchart is diagrammatic representation of an algorithm. It is constructed using different types of boxes and symbols.  The flowchart employs a series of blocks and arrows, each of which represents a particular step in an algorithm  These are useful for detailed representations of complicated programs  For complex programs, Flowcharts prove to be adequate
  • 26. Symbols used in flowcharts: The symbols that we make use while drawing flowcharts as given below are as per conventions followed by International Standard Organization (ISO).  Oval: Rectangle with rounded sides is used to indicate either START/ STOP of the program.  Input and output indicators: Parallelograms are used to represent input and output operations. Statements like INPUT, READ and PRINT are represented in these Parallelograms.
  • 27. Process Indicators: - Rectangle is used to indicate any set of processing operation such as for storing arithmetic operations. Decision Makers: The diamond is used for indicating the step of decision making and therefore known as decision box. Decision boxes are used to test the conditions or ask questions and depending upon the answers, the appropriate actions are taken by the computer. The decision box symbol is Flow Lines: Flow lines indicate the direction being followed in the flowchart. In a Flowchart, every line must have an arrow on it to indicate the direction. The arrows may be in any direction
  • 28. On- Page connectors: Circles are used to join the different parts of a flowchart and these circles are called on-page connectors. The uses of these connectors give a neat shape to the flowcharts. Ina complicated problems, a flowchart may run in to several pages. The parts of the flowchart on different pages are to be joined with each other. The parts to be joined are indicated by the circle. Off-page connectors: This connector represents a break in the path of flowchart which is too large to fit on a single page. It is similar to on-page connector. The connector symbol marks where the algorithm ends on the first page and where it continues on the second
  • 29. Example: Draw a flowchart for adding the integers from 1 to 100 and to print the sum. Start Sum=0 N=1 Stop Is N>100? Print Sum Sum=Sum+N N=N+1 Yes No
  • 30. Try it yourself:  Draw the Flowchart to find Roots of Quadratic equation a𝑥2 + b𝑥 + c = 0. The coefficients a, b, c are the input data.  Draw a flowchart to find out the biggest of the three unequal positive numbers.  Draw a flowchart to find the factorial of given positive integer N.  ABC company plans to give a 6% year-end bonus to each of its employees earning $6,000 or more per month , and a fixed $250/- - bonus to the remaining employees. Draw a flowchart for calculating the bonus for an employee
  • 31. Pseudo Codes ❑ The Pseudo code is neither an algorithm nor a program. ❑ It is an abstract form of a program. It consists of English like statements which perform the specific operations. ❑ It is defined for an algorithm. ❑ It does not use any graphical representation. ❑ In pseudo code, the program is represented in terms of words and phrases, but the syntax of program is not strictly followed.
  • 32. Advantages of Pseudo Code:  Easy to read  Easy to understand  Easy to modify
  • 33. Example: Write a pseudo code to perform the basic arithmetic operations.  Read n1, n2  Sum = n1 + n2  Diff = n1 – n2  Mult = n1 * n2  Quot = n1/n2  Print sum, diff, mult, quot  End.