SlideShare a Scribd company logo
PROBLEM SOLVING
METHODOLOGY
Prof. K ADISESHA (Ph. D)
Contents-
Introduction
Programming Error
Programming Constructs
Programming Approaches
2
Prof. K. Adisesha (Ph. D)
Problem-solving process
Programming techniques
INTRODUCTION
Prof. K. Adisesha (Ph. D)
3
Definition:
“Computer is an electronic machine that can store, recall and process
data. It can perform tasks or complex calculation according to a set of
instructions or programs.”
 The term problem solving is used in many disciplines, sometimes with
different perspectives and often with different terminologies.
 The problem-solving process starts with the problem specification and
end with a correct program.
PROBLEM SOLVING
Problem-solving process:
The steps to follow in the problem-solving process are:
 Problem definition
 Problem Analysis
 Problem Designing
o Algorithm, Flow Chart and Pseudo-code development
 Coding
 Testing & Debugging
 Documentation & Maintenance
Prof. K. Adisesha (Ph. D)
4
PROBLEM SOLVING
Problem definition:
The problem solver must understand problem very well to solve problem
efficiently:
 This step defines the problem thoroughly.
 Here requirements are specified.
 This step includes understanding the problem very well.
Prof. K. Adisesha (Ph. D)
5
PROBLEM SOLVING
Problem Analysis:
Analyzing the problem or analysis involves identifying the following:
 Inputs, i.e. the data you have to work with.
 Outputs i.e. the desired results.
 Any additional requirements on the solutions.
Prof. K. Adisesha (Ph. D)
6
PROBLEM SOLVING
ALGORITHM:
An Algorithm is a step-by-step procedure to solve a given problem:
 The word algorithm originates from the word ‘algorism’ which
means process of doing arithmetic with Arabic numerals.
 In 9th-century Arab Mathematician, Mohammed Al-Khowarizmi,
who developed methods for solving problems which is, used specific
step-by-step instructions
Prof. K. Adisesha (Ph. D)
7
ALGORITHM
Characteristics of algorithm:
A well defined algorithm has the five basic characteristics as follows:
1. Input: Algorithm starts with procedural steps to accept input data. The algorithm
must accept one or more data to be processed.
2. Definite: Each operational step or operation must be definite i.e. each and every
instruction must clearly specify that what should be done.
3. Effective: Each operational step can at least in principle is carried out by a person
using a paper and pencil in a minimum number of times.
4. Terminate: After some minimum number operation algorithm must come to an end.
5. Output: An algorithm is written to solve the problem, therefore it must produce one
or more computed result or answer called output.
Prof. K. Adisesha (Ph. D)
8
ALGORITHM
Example of algorithm:
Design an algorithm to find the area of a rectangle:
Given the length l and the breadth b, this algorithm finds the area of rectangle rec.
 Step 1: START
 Step 2: [Read the vales of l, b]
INPUT l, b
 Step 3: [Calculate are of rectangle]
rec = l * b
 Step 4: [Print the area of rectangle]
OUTPUT rec
 Step 5: [End of Algorithm]
STOPProf. K. Adisesha (Ph. D)
9
ALGORITHM
Example of algorithm:
Design an algorithm to find the average of four numbers:
 Step 1: START
 Step 2: INPUT A, B, C, D
 Step 3: [Calculate] AVG = (A+B+C+D)/4
 Step 4: OUTPUT AVG
 Step 5: STOP
Prof. K. Adisesha (Ph. D)
10
ALGORITHM
Advantage of Algorithm:
 It is a step-by-step representation of a 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 independent of programming language.
 It is easy to debug as every step has got its own logical sequence
Prof. K. Adisesha (Ph. D)
11
ALGORITHM
Disadvantage of Algorithm:
 It is time-consuming
 An algorithm is developed first which is converted into a flowchart and then into a
computer program.
Prof. K. Adisesha (Ph. D)
12
ALGORITHM
Analysis of Algorithm:
There may be more than one approach to solve a problem.
 The choice of a particular algorithm depends on the following performance analysis
and measurements.
 Space complexity: The amount of memory needed by the algorithm to complete
its run.
 Time Complexity: The amount of time, the algorithm needed to complete its
run.
Prof. K. Adisesha (Ph. D)
13
ALGORITHM
Analysis of Algorithm:
When we analyze an algorithm depends on input data, there are three
cases.
 Best Case
 Average Case
 Worst Case
Prof. K. Adisesha (Ph. D)
14
FLOWCHART
Definition:
A Flowchart is a pictorial or graphical representation of an algorithm.
 Flowchart plays an important role in the programming of a problem and helpful in
understanding the logic of program.
 Once the flow chart is drawn, it becomes easy to write program in any high level
language.
 Flowcharts are classified into two categories:
 Program Flowcharts
 System Flowcharts
Prof. K. Adisesha (Ph. D)
15
FLOWCHART
Definition:
A Flowchart is a pictorial or graphical representation of an algorithm.
 Program Flowcharts:
 Program flowcharts present a diagrammatic representation of a sequence of
instructions for solving a program.
 System flowcharts:
 System flowcharts indicate the flow of data throughout a data processing
system, as well as the flow into and out of the system.
 Such flowcharts are widely used by designers, to explain a data processing
system.
Prof. K. Adisesha (Ph. D)
16
FLOWCHART
Importance of Flowchart:
 Communication: Flowcharts are better way of communication of the logic of a
program.
 Effective Analysis: With the help of flowchart, problem can be analyzed in more
effective way.
 Proper documentation: Program flowcharts serve as a good program documentation,
which is needed for various programs.
 Efficient coding: The flowchart acts as guide or blueprint during the system analysis
and program development phase.
 Proper Debugging: The flow chart helps in debugging process.
 Efficient program maintenance: The maintenance of a program become easy with
the help of flowcharts.Prof. K. Adisesha (Ph. D)
17
FLOWCHART
Symbols Used In Flowcharts:
Prof. K. Adisesha (Ph. D)
18
FLOWCHART
Symbols Used In Flowcharts:
Prof. K. Adisesha (Ph. D)
19
FLOWCHART
Example of Flowcharts:
Prof. K. Adisesha (Ph. D)
20
FLOWCHART
Example of Flowcharts:
Prof. K. Adisesha (Ph. D)
21
FLOWCHART
Advantage of Flowcharts:
 Flowcharts provide an excellent means of communication, which is very easy
to understand.
 It has got a definite procedure, which shows all the major parts of a program,
It is easy to convert it into a program.
 It is independent of programming language.
 It is easy to debug as every step has got its own logical sequence.
Prof. K. Adisesha (Ph. D)
22
FLOWCHART
Disadvantages of Flowcharts:
 It is time-consuming and it requires the uses of a number of symbols which
are to be properly represented.
 The represented of complex logic is difficult in a flowchart.
 Alterations and modifications can be only made by redrawing the flowcharts.
Prof. K. Adisesha (Ph. D)
23
PSEUDO CODE:
Definition:
This is an abstract representation of program in English statement. .
 In Pseudo code English words & phrases are used to represent operations.
 Advantages:
 Easy to read, understand & modify.
 Disadvantages:
 It is only a partial code.
 It cannot be used to execute the and obtain the result.
Prof. K. Adisesha (Ph. D)
24
PROBLEM SOLVING
Coding or Programming:
The process of writing program instructions for an analyzed problem in a
programming language.
 It is the process of translating the algorithm or flowchart into the syntax of
given purpose language.
 You must convert each step of the algorithm into one or more statements in a
programming language such as C, C++, and Java etc.
Prof. K. Adisesha (Ph. D)
25
PROBLEM SOLVING
Testing and Debugging:
Testing:
 It is the process of checking whether the program works according to
the requirement of the user.
Debugging:
 It is the process of identifying and correcting or removing the Bugs
(errors).
Prof. K. Adisesha (Ph. D)
26
PROBLEM SOLVING
Testing and Debugging:
 There are four types of errors.
 Syntax errors
 Run-time errors
 Semantic errors
 Logic errors (bugs)
Prof. K. Adisesha (Ph. D)
27
ERRORS
Syntax Error:
 Syntax is the set of rules which should followed while creating the statements of
the program.
 The grammatical mistakes in the statements of the program are called syntax errors.
 Example: void main( )
{ int a, b;
cout << ‘Enter the numbers”
cin >> a >> b;
cout << a + b
}
 In the example program, the Second & fourth statement produces an syntax error as the
missing semicolon.Prof. K. Adisesha (Ph. D)
28
ERRORS
Semantic Error:
 An error, which occurs due to improper use of statements in programming language.
o Consider an expression C = A + B, indicating the values of the variable A and B are added
and assigned to variable C.
o If we written A + B = C, through the values of A and B are added, it cannot be assigned to
variable C written to the right of = Sign.
 This is semantic error
Run-time Error:
 During execution of the program, some errors may occur.
 Such errors are called run-time errors.
 Example: Divide by zero.
Prof. K. Adisesha (Ph. D)
29
ERRORS
Logical Error:
Logical errors occur when there are mistakes in the logic of the program.
 Unlike other errors logical errors are not displayed while compiling because the
compiler does not understand the logic of the program.
 Example:
o To find the area of the circle, the formula to be used is area = 3.14 * r * r.
o But if we written area = 3.14 * 2 * r, then the required output is not obtained
even though the program is successfully executed.
Prof. K. Adisesha (Ph. D)
30
PROBLEM SOLVING
Documentation and Maintenance:
Documentation is a reference material which explains the use and maintenance
of the program application for which it has been written.
 There are two types of documentation.
o Internal Documentation
o External Documentation.
Prof. K. Adisesha (Ph. D)
31
DOCUMENTATION
Internal Documentation:
This is also known as technical documentation.
 It is meant for the programmer who may update the program code at later
stages.
 It is done by:
o Defining meaningful variable names.
o Including comments in program code.
o Presenting the program code clearly.
Prof. K. Adisesha (Ph. D)
32
DOCUMENTATION
External Documentation:
The program or application is supported with additional textual
information about the application.
 It is useful for the user, administrator or developer.
Prof. K. Adisesha (Ph. D)
33
MAINTENANCE
Maintenance:
Program maintenance means periodic review of the programs and
modifications based on user’s requirements.
 Documentation plays an important role in program maintenance.
 It helps speedy and efficient maintenance.
 Maintenance is a continuous task
Prof. K. Adisesha (Ph. D)
34
PROGRAMMING CONSTRUCTS
Programming Constructs:
A programming constructs is a statement in a program.
 There are 3 basic programming constructs.
 Sequential Constructs
 Selection Constructs
 Iteration Constructs
Prof. K. Adisesha (Ph. D)
35
PROGRAMMING CONSTRUCTS
Sequential Constructs:
The program statements are executed one after another, in a sequence.
 Sequential constructs are.
 Input Statement
 Assignment Statement
 Output Statement
Prof. K. Adisesha (Ph. D)
36
PROGRAMMING CONSTRUCTS
Sequential Constructs:
Input Statement:
 This statement is used to input values into the variables from the input device.
 Example: INPUT A, B, C
Assignment Statement:
 This statement is used to store a value in a variable.
 In many languages ‘=’ is used as the assignment operator.
 Example: A = 10;
B = 5;
C = A + B;
Output Statement:
 This statement is used to display the values of variables on the standard output device.
 Example: OUTPUT C;
Prof. K. Adisesha (Ph. D)
37
PROGRAMMING CONSTRUCTS
Selection construct:
It is also known as conditional construct.
 This structure helps the programmer to take appropriate decision.
 There are five kinds of selection constructs, viz.
 Simple – if
 if – else
 if – else – if
 Nested – if
 Multiple Selection
Prof. K. Adisesha (Ph. D)
38
PROGRAMMING CONSTRUCTS
Iterative Constructs or Looping:
The process of repeated execution of a sequence of statements until some
condition is satisfied is called as iteration or repetition or loop.
 Iterative statements are also called as repetitive statement or looping
statements.
 There are two iterative constructs, viz.
 Conditional Looping
 Unconditional Looping
Prof. K. Adisesha (Ph. D)
39
ITERATIVE CONSTRUCTS
Conditional Looping:
This statement executes a group of instructions repeatedly until some
logical condition is satisfied.
 The number of repetitions will not be known in advance.
 The two conditional looping constructs are:
 While loop:
 This is a pre-tested loop structure.
 This structure checks the condition at the beginning of the structure
 do-while loop:
 This is a post-tested loop structure.
 This structure checks the condition at the end of the structureProf. K. Adisesha (Ph. D)
40
ITERATIVE CONSTRUCTS
Unconditional Looping:
This statement executes a group of instructions is repeated for specified
number of times.
 The unconditional looping constructs is:
 for statement:
 This structure is the fixed execution structure.
 This structure is usually used when we know in advance exactly how many
times asset of statements is to be repeatedly executed again and again.
 The general form of for structure is as follows:
for ( Expression 1; Expression 2; Expression 3)
{ Statements; }
Prof. K. Adisesha (Ph. D)
41
PROGRAMMING CONSTRUCTS
Characteristics of a good program:
The best program to solve a given problem is one that requires less space in memory,
takes less execution time, easy to modify and portable:
 Modification: A good program is the one which allows any modifications easily
whenever needed.
 Portability: A good program is the one which can be run on different type of machine
with a minimum or no change.
Prof. K. Adisesha (Ph. D)
42
PROGRAMMING APPROACHES
Approaches to problem solving:
The various approaches to solve a problems depends upon various problem designing
methods, in which system details are developed first, followed by major process.
 The various approaches are:
 Top-down design
 Stepwise refinement
 Bottom-up design
Prof. K. Adisesha (Ph. D)
43
PROGRAMMING APPROACHES
Approaches to problem solving:
Top-down design:
 Top-down design involves dividing a problem into sub-problems and further dividing the sub- problems
into smaller sub-problems until it leads to sub-problems that can be implemented as program statements.
Stepwise refinement:
 The process of breaking down the problem at each stage to obtain a computer solution is called stepwise
refinement
Bottom-up design:
 A design method, in which system details are developed first, followed by major process. This approach
is the reverse of top-down design.
 The process starts with identification of set of modules which are either available or to be constructed. An
attempt is made to combine the lower level modules to form modules of high level.
 Examples include object oriented programming using C++.
Prof. K. Adisesha (Ph. D)
44
PROGRAMMING APPROACHES
Programming techniques:
The various programming techniques are:
 Unstructured programming
 Procedural programming
 Structured programming
 Modular programming
Prof. K. Adisesha (Ph. D)
45
PROGRAMMING TECHNIQUES
Unstructured programming:
 During learning stage by writing small and simple programs
without planning leads to unstructured programming.
Procedural programming:
 This method allows us to combine the returning sequences of
statements into one single place.
 A procedure call is used to invoke the procedure. After the sequence is processed,
flow of control proceeds right after the position where the call was made.
 Procedures (sub procedures) programs can now be written as more structured and
error Free.
Prof. K. Adisesha (Ph. D)
46
PROGRAMMING TECHNIQUES
Structured programming:
 Structured programming is method of programming by using the following type of
code structures to write program:
 Sequence (input, output, assignment)
 Selection (if, if-else etc.)
 Iteration (while, do-while, for)
 Subroutines (functions)
Prof. K. Adisesha (Ph. D)
47
PROGRAMMING TECHNIQUES
Modular programming:
The process of splitting the lengthier and complex programs into number of smaller units
(modules) is called modularization and programming with such an approach is called
modular programming.
 This technique provides grouping of procedures which are common functionality into
separate modules.
 Advantages of modular programming:
 Reusability
 Debugging is easier
 Building library
 Portability
Prof. K. Adisesha (Ph. D)
48
Discussion
Prof. K. Adisesha (Ph. D)
49
Queries ?
Prof. K. Adisesha
9449081542

More Related Content

PPTX
Introduction to programming
PPT
Operators in C++
PDF
Control Structures in Python
PPT
Decision making and branching
PPTX
Exception handling in c++
PPT
While loop
PPTX
Loop(for, while, do while) condition Presentation
PDF
Input and Output
Introduction to programming
Operators in C++
Control Structures in Python
Decision making and branching
Exception handling in c++
While loop
Loop(for, while, do while) condition Presentation
Input and Output

What's hot (20)

PPTX
Input and Output In C Language
PPTX
Data Type Conversion in C++
PPTX
Control structures in c++
PPT
PPTX
Decision making statements in C programming
PPTX
Operators and expressions in c language
PPTX
PPTX
Presentation on C programming language
PPTX
Algorithm and flowchart
PPTX
Algorithm and pseudo codes
PPTX
POP vs OOP Introduction
PPT
FUNCTIONS IN c++ PPT
PPTX
Operators and expressions in C++
PPTX
Macro Processor
PDF
DATABASE MANAGEMENT SYSTEM LAB.pdf
PPTX
Operators and expressions
PPTX
Data Type in C Programming
PPTX
Control statements in c
PPTX
C keywords and identifiers
PPTX
Programming in C Presentation upto FILE
Input and Output In C Language
Data Type Conversion in C++
Control structures in c++
Decision making statements in C programming
Operators and expressions in c language
Presentation on C programming language
Algorithm and flowchart
Algorithm and pseudo codes
POP vs OOP Introduction
FUNCTIONS IN c++ PPT
Operators and expressions in C++
Macro Processor
DATABASE MANAGEMENT SYSTEM LAB.pdf
Operators and expressions
Data Type in C Programming
Control statements in c
C keywords and identifiers
Programming in C Presentation upto FILE
Ad

Similar to Problem solving methodology (20)

PDF
Problem solving methodology
PPTX
Module 1 python.pptx
PPTX
Introduction to computer science
PPTX
lecture 5
PPTX
UNIT-1.pptx python for engineering first year students
PPT
Unit 1 python (2021 r)
PDF
GE3151 PSPP _Unit 1 notes and Question bank.pdf
PDF
Study Material for Problem Solving Techniques
PPSX
CC-112-Lec.1.ppsx
PDF
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
PPTX
Algrithms and frowcharts.pptx
PPT
part_1 (1).ppt
PPTX
Introduction to problem solving Techniques
PPTX
Algorithm,Pseudocode,Flowchart.pptx
PPT
Part 1.ppt
PPT
Chapter 1.ppt
PPT
Problem solving using Computer
PDF
Python Unit 1.pdfPython Notes for Bharathiar university syllabus
PPTX
Programming C ppt for learning foundations
PPTX
Problem solving process
Problem solving methodology
Module 1 python.pptx
Introduction to computer science
lecture 5
UNIT-1.pptx python for engineering first year students
Unit 1 python (2021 r)
GE3151 PSPP _Unit 1 notes and Question bank.pdf
Study Material for Problem Solving Techniques
CC-112-Lec.1.ppsx
PROGRAMMING IN C UNIT I.pdffffffffffffffffffffffffd
Algrithms and frowcharts.pptx
part_1 (1).ppt
Introduction to problem solving Techniques
Algorithm,Pseudocode,Flowchart.pptx
Part 1.ppt
Chapter 1.ppt
Problem solving using Computer
Python Unit 1.pdfPython Notes for Bharathiar university syllabus
Programming C ppt for learning foundations
Problem solving process
Ad

More from Prof. Dr. K. Adisesha (20)

PDF
MACHINE LEARNING Notes by Dr. K. Adisesha
PDF
Probabilistic and Stochastic Models Unit-3-Adi.pdf
PDF
Genetic Algorithm in Machine Learning PPT by-Adi
PDF
Unsupervised Machine Learning PPT Adi.pdf
PDF
Supervised Machine Learning PPT by K. Adisesha
PDF
Introduction to Machine Learning PPT by K. Adisesha
PPSX
Design and Analysis of Algorithms ppt by K. Adi
PPSX
Data Structure using C by Dr. K Adisesha .ppsx
PDF
Operating System-4 "File Management" by Adi.pdf
PDF
Operating System-3 "Memory Management" by Adi.pdf
PDF
Operating System Concepts Part-1 by_Adi.pdf
PDF
Operating System-2_Process Managementby_Adi.pdf
PDF
Software Engineering notes by K. Adisesha.pdf
PDF
Software Engineering-Unit 1 by Adisesha.pdf
PDF
Software Engineering-Unit 2 "Requirement Engineering" by Adi.pdf
PDF
Software Engineering-Unit 3 "System Modelling" by Adi.pdf
PDF
Software Engineering-Unit 4 "Architectural Design" by Adi.pdf
PDF
Software Engineering-Unit 5 "Software Testing"by Adi.pdf
PDF
Computer Networks Notes by -Dr. K. Adisesha
PDF
CCN Unit-1&2 Data Communication &Networking by K. Adiaesha
MACHINE LEARNING Notes by Dr. K. Adisesha
Probabilistic and Stochastic Models Unit-3-Adi.pdf
Genetic Algorithm in Machine Learning PPT by-Adi
Unsupervised Machine Learning PPT Adi.pdf
Supervised Machine Learning PPT by K. Adisesha
Introduction to Machine Learning PPT by K. Adisesha
Design and Analysis of Algorithms ppt by K. Adi
Data Structure using C by Dr. K Adisesha .ppsx
Operating System-4 "File Management" by Adi.pdf
Operating System-3 "Memory Management" by Adi.pdf
Operating System Concepts Part-1 by_Adi.pdf
Operating System-2_Process Managementby_Adi.pdf
Software Engineering notes by K. Adisesha.pdf
Software Engineering-Unit 1 by Adisesha.pdf
Software Engineering-Unit 2 "Requirement Engineering" by Adi.pdf
Software Engineering-Unit 3 "System Modelling" by Adi.pdf
Software Engineering-Unit 4 "Architectural Design" by Adi.pdf
Software Engineering-Unit 5 "Software Testing"by Adi.pdf
Computer Networks Notes by -Dr. K. Adisesha
CCN Unit-1&2 Data Communication &Networking by K. Adiaesha

Recently uploaded (20)

PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
PSYCHOLOGY IN EDUCATION.pdf ( nice pdf ...)
PDF
Insiders guide to clinical Medicine.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Open Quiz Monsoon Mind Game Prelims.pptx
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Pre independence Education in Inndia.pdf
PDF
The Final Stretch: How to Release a Game and Not Die in the Process.
PPTX
NOI Hackathon - Summer Edition - GreenThumber.pptx
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Electrolyte Disturbances and Fluid Management A clinical and physiological ap...
PPTX
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
PDF
English Language Teaching from Post-.pdf
PPTX
Cell Structure & Organelles in detailed.
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
From loneliness to social connection charting
PDF
Business Ethics Teaching Materials for college
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
Mga Unang Hakbang Tungo Sa Tao by Joe Vibar Nero.pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PSYCHOLOGY IN EDUCATION.pdf ( nice pdf ...)
Insiders guide to clinical Medicine.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Open Quiz Monsoon Mind Game Prelims.pptx
STATICS OF THE RIGID BODIES Hibbelers.pdf
Pre independence Education in Inndia.pdf
The Final Stretch: How to Release a Game and Not Die in the Process.
NOI Hackathon - Summer Edition - GreenThumber.pptx
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Electrolyte Disturbances and Fluid Management A clinical and physiological ap...
COMPUTERS AS DATA ANALYSIS IN PRECLINICAL DEVELOPMENT.pptx
English Language Teaching from Post-.pdf
Cell Structure & Organelles in detailed.
Renaissance Architecture: A Journey from Faith to Humanism
From loneliness to social connection charting
Business Ethics Teaching Materials for college
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Mga Unang Hakbang Tungo Sa Tao by Joe Vibar Nero.pdf

Problem solving methodology

  • 2. Contents- Introduction Programming Error Programming Constructs Programming Approaches 2 Prof. K. Adisesha (Ph. D) Problem-solving process Programming techniques
  • 3. INTRODUCTION Prof. K. Adisesha (Ph. D) 3 Definition: “Computer is an electronic machine that can store, recall and process data. It can perform tasks or complex calculation according to a set of instructions or programs.”  The term problem solving is used in many disciplines, sometimes with different perspectives and often with different terminologies.  The problem-solving process starts with the problem specification and end with a correct program.
  • 4. PROBLEM SOLVING Problem-solving process: The steps to follow in the problem-solving process are:  Problem definition  Problem Analysis  Problem Designing o Algorithm, Flow Chart and Pseudo-code development  Coding  Testing & Debugging  Documentation & Maintenance Prof. K. Adisesha (Ph. D) 4
  • 5. PROBLEM SOLVING Problem definition: The problem solver must understand problem very well to solve problem efficiently:  This step defines the problem thoroughly.  Here requirements are specified.  This step includes understanding the problem very well. Prof. K. Adisesha (Ph. D) 5
  • 6. PROBLEM SOLVING Problem Analysis: Analyzing the problem or analysis involves identifying the following:  Inputs, i.e. the data you have to work with.  Outputs i.e. the desired results.  Any additional requirements on the solutions. Prof. K. Adisesha (Ph. D) 6
  • 7. PROBLEM SOLVING ALGORITHM: An Algorithm is a step-by-step procedure to solve a given problem:  The word algorithm originates from the word ‘algorism’ which means process of doing arithmetic with Arabic numerals.  In 9th-century Arab Mathematician, Mohammed Al-Khowarizmi, who developed methods for solving problems which is, used specific step-by-step instructions Prof. K. Adisesha (Ph. D) 7
  • 8. ALGORITHM Characteristics of algorithm: A well defined algorithm has the five basic characteristics as follows: 1. Input: Algorithm starts with procedural steps to accept input data. The algorithm must accept one or more data to be processed. 2. Definite: Each operational step or operation must be definite i.e. each and every instruction must clearly specify that what should be done. 3. Effective: Each operational step can at least in principle is carried out by a person using a paper and pencil in a minimum number of times. 4. Terminate: After some minimum number operation algorithm must come to an end. 5. Output: An algorithm is written to solve the problem, therefore it must produce one or more computed result or answer called output. Prof. K. Adisesha (Ph. D) 8
  • 9. ALGORITHM Example of algorithm: Design an algorithm to find the area of a rectangle: Given the length l and the breadth b, this algorithm finds the area of rectangle rec.  Step 1: START  Step 2: [Read the vales of l, b] INPUT l, b  Step 3: [Calculate are of rectangle] rec = l * b  Step 4: [Print the area of rectangle] OUTPUT rec  Step 5: [End of Algorithm] STOPProf. K. Adisesha (Ph. D) 9
  • 10. ALGORITHM Example of algorithm: Design an algorithm to find the average of four numbers:  Step 1: START  Step 2: INPUT A, B, C, D  Step 3: [Calculate] AVG = (A+B+C+D)/4  Step 4: OUTPUT AVG  Step 5: STOP Prof. K. Adisesha (Ph. D) 10
  • 11. ALGORITHM Advantage of Algorithm:  It is a step-by-step representation of a 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 independent of programming language.  It is easy to debug as every step has got its own logical sequence Prof. K. Adisesha (Ph. D) 11
  • 12. ALGORITHM Disadvantage of Algorithm:  It is time-consuming  An algorithm is developed first which is converted into a flowchart and then into a computer program. Prof. K. Adisesha (Ph. D) 12
  • 13. ALGORITHM Analysis of Algorithm: There may be more than one approach to solve a problem.  The choice of a particular algorithm depends on the following performance analysis and measurements.  Space complexity: The amount of memory needed by the algorithm to complete its run.  Time Complexity: The amount of time, the algorithm needed to complete its run. Prof. K. Adisesha (Ph. D) 13
  • 14. ALGORITHM Analysis of Algorithm: When we analyze an algorithm depends on input data, there are three cases.  Best Case  Average Case  Worst Case Prof. K. Adisesha (Ph. D) 14
  • 15. FLOWCHART Definition: A Flowchart is a pictorial or graphical representation of an algorithm.  Flowchart plays an important role in the programming of a problem and helpful in understanding the logic of program.  Once the flow chart is drawn, it becomes easy to write program in any high level language.  Flowcharts are classified into two categories:  Program Flowcharts  System Flowcharts Prof. K. Adisesha (Ph. D) 15
  • 16. FLOWCHART Definition: A Flowchart is a pictorial or graphical representation of an algorithm.  Program Flowcharts:  Program flowcharts present a diagrammatic representation of a sequence of instructions for solving a program.  System flowcharts:  System flowcharts indicate the flow of data throughout a data processing system, as well as the flow into and out of the system.  Such flowcharts are widely used by designers, to explain a data processing system. Prof. K. Adisesha (Ph. D) 16
  • 17. FLOWCHART Importance of Flowchart:  Communication: Flowcharts are better way of communication of the logic of a program.  Effective Analysis: With the help of flowchart, problem can be analyzed in more effective way.  Proper documentation: Program flowcharts serve as a good program documentation, which is needed for various programs.  Efficient coding: The flowchart acts as guide or blueprint during the system analysis and program development phase.  Proper Debugging: The flow chart helps in debugging process.  Efficient program maintenance: The maintenance of a program become easy with the help of flowcharts.Prof. K. Adisesha (Ph. D) 17
  • 18. FLOWCHART Symbols Used In Flowcharts: Prof. K. Adisesha (Ph. D) 18
  • 19. FLOWCHART Symbols Used In Flowcharts: Prof. K. Adisesha (Ph. D) 19
  • 20. FLOWCHART Example of Flowcharts: Prof. K. Adisesha (Ph. D) 20
  • 21. FLOWCHART Example of Flowcharts: Prof. K. Adisesha (Ph. D) 21
  • 22. FLOWCHART Advantage of Flowcharts:  Flowcharts provide an excellent means of communication, which is very easy to understand.  It has got a definite procedure, which shows all the major parts of a program, It is easy to convert it into a program.  It is independent of programming language.  It is easy to debug as every step has got its own logical sequence. Prof. K. Adisesha (Ph. D) 22
  • 23. FLOWCHART Disadvantages of Flowcharts:  It is time-consuming and it requires the uses of a number of symbols which are to be properly represented.  The represented of complex logic is difficult in a flowchart.  Alterations and modifications can be only made by redrawing the flowcharts. Prof. K. Adisesha (Ph. D) 23
  • 24. PSEUDO CODE: Definition: This is an abstract representation of program in English statement. .  In Pseudo code English words & phrases are used to represent operations.  Advantages:  Easy to read, understand & modify.  Disadvantages:  It is only a partial code.  It cannot be used to execute the and obtain the result. Prof. K. Adisesha (Ph. D) 24
  • 25. PROBLEM SOLVING Coding or Programming: The process of writing program instructions for an analyzed problem in a programming language.  It is the process of translating the algorithm or flowchart into the syntax of given purpose language.  You must convert each step of the algorithm into one or more statements in a programming language such as C, C++, and Java etc. Prof. K. Adisesha (Ph. D) 25
  • 26. PROBLEM SOLVING Testing and Debugging: Testing:  It is the process of checking whether the program works according to the requirement of the user. Debugging:  It is the process of identifying and correcting or removing the Bugs (errors). Prof. K. Adisesha (Ph. D) 26
  • 27. PROBLEM SOLVING Testing and Debugging:  There are four types of errors.  Syntax errors  Run-time errors  Semantic errors  Logic errors (bugs) Prof. K. Adisesha (Ph. D) 27
  • 28. ERRORS Syntax Error:  Syntax is the set of rules which should followed while creating the statements of the program.  The grammatical mistakes in the statements of the program are called syntax errors.  Example: void main( ) { int a, b; cout << ‘Enter the numbers” cin >> a >> b; cout << a + b }  In the example program, the Second & fourth statement produces an syntax error as the missing semicolon.Prof. K. Adisesha (Ph. D) 28
  • 29. ERRORS Semantic Error:  An error, which occurs due to improper use of statements in programming language. o Consider an expression C = A + B, indicating the values of the variable A and B are added and assigned to variable C. o If we written A + B = C, through the values of A and B are added, it cannot be assigned to variable C written to the right of = Sign.  This is semantic error Run-time Error:  During execution of the program, some errors may occur.  Such errors are called run-time errors.  Example: Divide by zero. Prof. K. Adisesha (Ph. D) 29
  • 30. ERRORS Logical Error: Logical errors occur when there are mistakes in the logic of the program.  Unlike other errors logical errors are not displayed while compiling because the compiler does not understand the logic of the program.  Example: o To find the area of the circle, the formula to be used is area = 3.14 * r * r. o But if we written area = 3.14 * 2 * r, then the required output is not obtained even though the program is successfully executed. Prof. K. Adisesha (Ph. D) 30
  • 31. PROBLEM SOLVING Documentation and Maintenance: Documentation is a reference material which explains the use and maintenance of the program application for which it has been written.  There are two types of documentation. o Internal Documentation o External Documentation. Prof. K. Adisesha (Ph. D) 31
  • 32. DOCUMENTATION Internal Documentation: This is also known as technical documentation.  It is meant for the programmer who may update the program code at later stages.  It is done by: o Defining meaningful variable names. o Including comments in program code. o Presenting the program code clearly. Prof. K. Adisesha (Ph. D) 32
  • 33. DOCUMENTATION External Documentation: The program or application is supported with additional textual information about the application.  It is useful for the user, administrator or developer. Prof. K. Adisesha (Ph. D) 33
  • 34. MAINTENANCE Maintenance: Program maintenance means periodic review of the programs and modifications based on user’s requirements.  Documentation plays an important role in program maintenance.  It helps speedy and efficient maintenance.  Maintenance is a continuous task Prof. K. Adisesha (Ph. D) 34
  • 35. PROGRAMMING CONSTRUCTS Programming Constructs: A programming constructs is a statement in a program.  There are 3 basic programming constructs.  Sequential Constructs  Selection Constructs  Iteration Constructs Prof. K. Adisesha (Ph. D) 35
  • 36. PROGRAMMING CONSTRUCTS Sequential Constructs: The program statements are executed one after another, in a sequence.  Sequential constructs are.  Input Statement  Assignment Statement  Output Statement Prof. K. Adisesha (Ph. D) 36
  • 37. PROGRAMMING CONSTRUCTS Sequential Constructs: Input Statement:  This statement is used to input values into the variables from the input device.  Example: INPUT A, B, C Assignment Statement:  This statement is used to store a value in a variable.  In many languages ‘=’ is used as the assignment operator.  Example: A = 10; B = 5; C = A + B; Output Statement:  This statement is used to display the values of variables on the standard output device.  Example: OUTPUT C; Prof. K. Adisesha (Ph. D) 37
  • 38. PROGRAMMING CONSTRUCTS Selection construct: It is also known as conditional construct.  This structure helps the programmer to take appropriate decision.  There are five kinds of selection constructs, viz.  Simple – if  if – else  if – else – if  Nested – if  Multiple Selection Prof. K. Adisesha (Ph. D) 38
  • 39. PROGRAMMING CONSTRUCTS Iterative Constructs or Looping: The process of repeated execution of a sequence of statements until some condition is satisfied is called as iteration or repetition or loop.  Iterative statements are also called as repetitive statement or looping statements.  There are two iterative constructs, viz.  Conditional Looping  Unconditional Looping Prof. K. Adisesha (Ph. D) 39
  • 40. ITERATIVE CONSTRUCTS Conditional Looping: This statement executes a group of instructions repeatedly until some logical condition is satisfied.  The number of repetitions will not be known in advance.  The two conditional looping constructs are:  While loop:  This is a pre-tested loop structure.  This structure checks the condition at the beginning of the structure  do-while loop:  This is a post-tested loop structure.  This structure checks the condition at the end of the structureProf. K. Adisesha (Ph. D) 40
  • 41. ITERATIVE CONSTRUCTS Unconditional Looping: This statement executes a group of instructions is repeated for specified number of times.  The unconditional looping constructs is:  for statement:  This structure is the fixed execution structure.  This structure is usually used when we know in advance exactly how many times asset of statements is to be repeatedly executed again and again.  The general form of for structure is as follows: for ( Expression 1; Expression 2; Expression 3) { Statements; } Prof. K. Adisesha (Ph. D) 41
  • 42. PROGRAMMING CONSTRUCTS Characteristics of a good program: The best program to solve a given problem is one that requires less space in memory, takes less execution time, easy to modify and portable:  Modification: A good program is the one which allows any modifications easily whenever needed.  Portability: A good program is the one which can be run on different type of machine with a minimum or no change. Prof. K. Adisesha (Ph. D) 42
  • 43. PROGRAMMING APPROACHES Approaches to problem solving: The various approaches to solve a problems depends upon various problem designing methods, in which system details are developed first, followed by major process.  The various approaches are:  Top-down design  Stepwise refinement  Bottom-up design Prof. K. Adisesha (Ph. D) 43
  • 44. PROGRAMMING APPROACHES Approaches to problem solving: Top-down design:  Top-down design involves dividing a problem into sub-problems and further dividing the sub- problems into smaller sub-problems until it leads to sub-problems that can be implemented as program statements. Stepwise refinement:  The process of breaking down the problem at each stage to obtain a computer solution is called stepwise refinement Bottom-up design:  A design method, in which system details are developed first, followed by major process. This approach is the reverse of top-down design.  The process starts with identification of set of modules which are either available or to be constructed. An attempt is made to combine the lower level modules to form modules of high level.  Examples include object oriented programming using C++. Prof. K. Adisesha (Ph. D) 44
  • 45. PROGRAMMING APPROACHES Programming techniques: The various programming techniques are:  Unstructured programming  Procedural programming  Structured programming  Modular programming Prof. K. Adisesha (Ph. D) 45
  • 46. PROGRAMMING TECHNIQUES Unstructured programming:  During learning stage by writing small and simple programs without planning leads to unstructured programming. Procedural programming:  This method allows us to combine the returning sequences of statements into one single place.  A procedure call is used to invoke the procedure. After the sequence is processed, flow of control proceeds right after the position where the call was made.  Procedures (sub procedures) programs can now be written as more structured and error Free. Prof. K. Adisesha (Ph. D) 46
  • 47. PROGRAMMING TECHNIQUES Structured programming:  Structured programming is method of programming by using the following type of code structures to write program:  Sequence (input, output, assignment)  Selection (if, if-else etc.)  Iteration (while, do-while, for)  Subroutines (functions) Prof. K. Adisesha (Ph. D) 47
  • 48. PROGRAMMING TECHNIQUES Modular programming: The process of splitting the lengthier and complex programs into number of smaller units (modules) is called modularization and programming with such an approach is called modular programming.  This technique provides grouping of procedures which are common functionality into separate modules.  Advantages of modular programming:  Reusability  Debugging is easier  Building library  Portability Prof. K. Adisesha (Ph. D) 48
  • 49. Discussion Prof. K. Adisesha (Ph. D) 49 Queries ? Prof. K. Adisesha 9449081542