SlideShare a Scribd company logo
PROBLEM SOLVING
USING PYTHON
INTRODUCTION
Prepared By,
Dr. S. Beulah / ASP/ NICHE
Ms. M. MERLIN JOHNSY / AP/ NICHE
PROBLEM SOLVING
Problem solving is the systematic approach to define the problem
and creating number of solutions.
The problem solving process starts with the problem specifications
and ends with a Correct program
PROBLEM SOLVING TECHNIQUES
Problem solving technique is a set of techniques that helps in
providing logic for solving a problem.
Problem Solving Techniques:
Problem solving can be expressed in the form of
1. Algorithms.
2. Flowcharts.
3. Pseudo codes.
4. programs
Algorithm Flowchart Pseudo code
Step by step process
written in normal
English language to
solve the given
problem.
Diagrammatic representation of the
solution
Similar to program.
Pseudo – False
Code - Program
Step 1 : Start
.
.
.
Step n :Stop
Input – READ, OBTAIN,
GET, PROMPT
Output – PRINT, DISPLAY,
SHOW
Compute – COMPUTE,
CALCULATE, DETERMINE
Initiate - SET, INITIALIZE
Add One – INCREMENT
ALGORITHM
It is defined as a sequence of instructions that describe a method for solving a
problem. In other words it is a step by step procedure for solving a problem.
Properties of Algorithms
v Should be written in simple English
v Each and every instruction should be precise and unambiguous.
v Instructions in an algorithm should not be repeated infinitely.
v Algorithm should conclude after a finite number of steps.
v Should have an end point
v Derived results should be obtained only after the algorithm terminates.
Qualities of a good algorithm
The following are the primary factors that are often used to judge the quality of the
algorithms.
Time – To execute a program, the computer system takes some amount of time.
The lesser is the time required, the better is the algorithm.
Memory – To execute a program, computer system takes some amount of
memory space. The lesser is the memory required, the better is the algorithm.
Accuracy – Multiple algorithms may provide suitable or correct solutions to a
given problem, some of these may provide more accurate results than others, and such
algorithms may be suitable.
Example
Write an algorithm to print „Good Morning”
Step 1: Start
Step 2: Print “Good Morning”
Step 3: Stop
BUILDING BLOCKS OF ALGORITHMS (statements, state, control flow, functions)
Algorithms can be constructed from basic building blocks namely, sequence, selection and iteration.
Statements:
Statement is a single action in a computer.
In a computer statements might include some of the following actions
Ø input data-information given to the program
Ø process data-perform operation on a given input
Ø output data-processed result
State:
Transition from one process to another process under specified condition with in a time is called state.
Control flow:
The process of executing the individual statements in a given order is called control flow.
The control can be executed in three ways
1. sequence
2. selection
3. iteration
Sequence:
All the instructions are executed one after another is called sequence
execution.
Example:
Add two numbers:
Step 1: Start
Step 2: get a,b
Step 3: calculate c=a+b
Step 4: Display c
Step 5: Stop
Selection:
A selection statement causes the program control to be transferred to a specific
part of the program based upon the condition.
If the conditional test is true, one part of the program will be executed,
otherwise it will execute the other part of the program.
Example
Write an algorithm to check whether he is eligible
to vote?
Step 1: Start
Step 2: Get age
Step 3: if age >= 18 print “Eligible to vote”
Step 4: else print “Not eligible to vote”
Step 6: Stop
Iteration:
In some programs, certain set of statements are executed again and again based upon conditional test.
i.e. executed more than one time. This type of execution is called looping or iteration.
Example
Write an algorithm to print all natural numbers up to n
Step 1: Start
Step 2: get n value.
Step 3: initialize i=1
Step 4: if (i<=n) go to step 5 else go to step 7
Step 5: Print i value and increment i value by 1
Step 6: go to step 4
Step 7: Stop
Functions:
v Function is a sub program which consists of block of code(set of instructions)
that performs a particular task.
v For complex problems, the problem is been divided into smaller and simpler
tasks during algorithm design.
Benefits of Using Functions
v Reduction in line of code
v code reuse
v Better readability
v Information hiding
v Easy to debug and test
v Improved maintainability
Example:
Algorithm for addition of two numbers using function
Main function()
Step 1: Start
Step 2: Call the function add()
Step 3: Stop
sub function add()
Step 1: Function start
Step 2: Get a, b Values
Step 3: add c=a+b
Step 4: Print c
Step 5: Return
NOTATIONS
FLOW CHART
• Flow chart is defined as graphical representation of the logic for
problem solving.
• The purpose of flowchart is making the logic of the program
clear in a visual representation.
Rules for drawing a flowchart
1. The flowchart should be clear, neat and easy to follow.
2. The flowchart must have a logical start and finish.
3. Only one flow line should come out from a process symbol.
4. Only one flow line should enter a decision symbol. However, two
or three flow lines may leave the decision symbol.
5. Only one flow line is used with a terminal symbol.
6. Within standard symbols, write briefly and precisely.
7. Intersection of flow lines should be avoided.
Advantages of flowchart:
1. Communication: - Flowcharts are better way of communicating the logic of
a system to all concerned.
2. Effective analysis: - With the help of flowchart, problem can be analysed in
more effective way.
3. Proper documentation: - Program flowcharts serve as a good program
documentation, which is needed for various purposes.
4. Efficient Coding: - The flowcharts act as a guide or blueprint during the
systems analysis and program development phase.
5. Proper Debugging: - The flowchart helps in debugging process.
6. Efficient Program Maintenance: - The maintenance of operating program
becomes easy with the help of flowchart. It helps the programmer to put
efforts more efficiently on that part.
Disadvantages of flow chart:
1. Complex logic: - Sometimes, the program logic is quite
complicated. In that case, flowchart becomes complex and clumsy.
2. Alterations and Modifications: - If alterations are required the
flowchart may require re-drawing completely.
3. Reproduction: - As the flowchart symbols cannot be typed,
reproduction of flowchart becomes a problem.
4. Cost: For large application the time and cost of flowchart drawing
becomes costly.
STEP1: START
STEP2: Get n value
STEP 3: if n % 2==0 then GOTO STEP 4 ,otherwise GOTO STEP 5
STEO4: PRINT N is EVEN number
STEP 5: PRINT N is ODD number
STEP6: STOP
PSEUDO CODE:
■ Pseudo code consists of short, readable and formally styled English
languages used for explain an algorithm.
■ It does not include details like variable declaration, subroutines.
■ It is easier to understand for the programmer or non programmer to
understand
■ the general working of the program, because it is not based on any
programming language.
■ It gives us the sketch of the program before actual coding.
■ It is not a machine readable
■ Pseudo code can’t be compiled and executed.
■ There is no standard syntax for pseudo code.
Guidelines for writing pseudo code:
■ Write one statement per line
■ Capitalize initial keyword
■ Indent to hierarchy
■ End multiline structure
■ Keep statements language independent
Common keywords used in pseudocode
The following gives common keywords used in pseudocodes.
1. //: This keyword used to represent a comment.
2. BEGIN,END: Begin is the first statement and end is the last statement.
3. INPUT, GET, READ: The keyword is used to inputting data.
4. COMPUTE, CALCULATE: used for calculation of the result of the given expression.
5. ADD, SUBTRACT, INITIALIZE used for addition, subtraction and initialization.
6. OUTPUT, PRINT, DISPLAY: It is used to display the output of the program.
7. IF, ELSE, ENDIF: used to make decision.
8. WHILE, ENDWHILE: used for iterative statements.
9. FOR, ENDFOR: Another iterative incremented/decremented tested automatically.
Introduction to problem solving Techniques
EVEN/ODD
Num=int(“Enter any value”)
IF(num%2==0)
PRINT(“ num even number”)
ELSE
PRINT (“num odd number”)
Advantages:
■ Pseudo is independent of any language; it can be used by
most programmers.
■ It is easy to translate pseudo code into a programming
language.
■ It can be easily modified as compared to flowchart.
■ Converting a pseudo code to programming language is very
easy as compared with converting a flowchart to programming
language.
Disadvantages:
■ It does not provide visual representation of the
program’s logic.
■ There are no accepted standards for writing pseudo
codes.
■ It cannot be compiled nor executed.
■ For a beginner, It is more difficult to follow the logic
or write pseudo code as compared to flowchart.
Example:
Addition of two numbers:
BEGIN
GET a,b
ADD c=a+b
PRINT c
END
Introduction to problem solving Techniques

More Related Content

PPT
Unit 1 python (2021 r)
PDF
Python Unit 1.pdfPython Notes for Bharathiar university syllabus
PDF
GE3151 PSPP _Unit 1 notes and Question bank.pdf
PPTX
Module 1 python.pptx
PDF
BCA 1st semester Problem Solving Notes using C.pdf
PPTX
UNIT 1.pptx
PDF
Algorithmic problem sloving
PPTX
Algorithm for computational problematic sit
Unit 1 python (2021 r)
Python Unit 1.pdfPython Notes for Bharathiar university syllabus
GE3151 PSPP _Unit 1 notes and Question bank.pdf
Module 1 python.pptx
BCA 1st semester Problem Solving Notes using C.pdf
UNIT 1.pptx
Algorithmic problem sloving
Algorithm for computational problematic sit

Similar to Introduction to problem solving Techniques (20)

DOCX
Chapter 2(1)
PDF
Problem solving methodology
PPT
UNIT-1-PPT-DESIGN AND ANALYSIS OF ALGORITHMS
PDF
Study Material for Problem Solving Techniques
PDF
Introduction to Computer Programming
PPTX
UNIT-1.pptx python for engineering first year students
PDF
Algorithms notes 2 tutorials duniya
PPTX
module1 new c programming for begginers.pptx
PPTX
Introduction to computer science
PPTX
lecture 5
PPTX
C LANGUAGE-FLOWCHARTS,PSEUDOCODE,ALGORITHMS APPROCHES
PPTX
C++ good tutorial
DOC
Program concep sequential statements
PPT
UNIT-1-PPTS-DAA.ppt
PPT
Introduction to Design Algorithm And Analysis.ppt
PPT
UNIT-1-PPTS-DAA.ppt
PPTX
Programming_Lecture_1.pptx
PPTX
PCCF UNIT 1.pptx
PPTX
01 Introduction to analysis of Algorithms.pptx
PPTX
Algorithms and flow charts
Chapter 2(1)
Problem solving methodology
UNIT-1-PPT-DESIGN AND ANALYSIS OF ALGORITHMS
Study Material for Problem Solving Techniques
Introduction to Computer Programming
UNIT-1.pptx python for engineering first year students
Algorithms notes 2 tutorials duniya
module1 new c programming for begginers.pptx
Introduction to computer science
lecture 5
C LANGUAGE-FLOWCHARTS,PSEUDOCODE,ALGORITHMS APPROCHES
C++ good tutorial
Program concep sequential statements
UNIT-1-PPTS-DAA.ppt
Introduction to Design Algorithm And Analysis.ppt
UNIT-1-PPTS-DAA.ppt
Programming_Lecture_1.pptx
PCCF UNIT 1.pptx
01 Introduction to analysis of Algorithms.pptx
Algorithms and flow charts
Ad

Recently uploaded (20)

PDF
Sports Quiz easy sports quiz sports quiz
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
01-Introduction-to-Information-Management.pdf
PPTX
master seminar digital applications in india
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
GDM (1) (1).pptx small presentation for students
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Complications of Minimal Access Surgery at WLH
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Cell Structure & Organelles in detailed.
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Insiders guide to clinical Medicine.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Lesson notes of climatology university.
Sports Quiz easy sports quiz sports quiz
Supply Chain Operations Speaking Notes -ICLT Program
Module 4: Burden of Disease Tutorial Slides S2 2025
01-Introduction-to-Information-Management.pdf
master seminar digital applications in india
PPH.pptx obstetrics and gynecology in nursing
GDM (1) (1).pptx small presentation for students
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Microbial diseases, their pathogenesis and prophylaxis
O5-L3 Freight Transport Ops (International) V1.pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
TR - Agricultural Crops Production NC III.pdf
Complications of Minimal Access Surgery at WLH
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Cell Structure & Organelles in detailed.
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Insiders guide to clinical Medicine.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Lesson notes of climatology university.
Ad

Introduction to problem solving Techniques

  • 1. PROBLEM SOLVING USING PYTHON INTRODUCTION Prepared By, Dr. S. Beulah / ASP/ NICHE Ms. M. MERLIN JOHNSY / AP/ NICHE
  • 2. PROBLEM SOLVING Problem solving is the systematic approach to define the problem and creating number of solutions. The problem solving process starts with the problem specifications and ends with a Correct program
  • 3. PROBLEM SOLVING TECHNIQUES Problem solving technique is a set of techniques that helps in providing logic for solving a problem. Problem Solving Techniques: Problem solving can be expressed in the form of 1. Algorithms. 2. Flowcharts. 3. Pseudo codes. 4. programs
  • 4. Algorithm Flowchart Pseudo code Step by step process written in normal English language to solve the given problem. Diagrammatic representation of the solution Similar to program. Pseudo – False Code - Program Step 1 : Start . . . Step n :Stop Input – READ, OBTAIN, GET, PROMPT Output – PRINT, DISPLAY, SHOW Compute – COMPUTE, CALCULATE, DETERMINE Initiate - SET, INITIALIZE Add One – INCREMENT
  • 5. ALGORITHM It is defined as a sequence of instructions that describe a method for solving a problem. In other words it is a step by step procedure for solving a problem. Properties of Algorithms v Should be written in simple English v Each and every instruction should be precise and unambiguous. v Instructions in an algorithm should not be repeated infinitely. v Algorithm should conclude after a finite number of steps. v Should have an end point v Derived results should be obtained only after the algorithm terminates.
  • 6. Qualities of a good algorithm The following are the primary factors that are often used to judge the quality of the algorithms. Time – To execute a program, the computer system takes some amount of time. The lesser is the time required, the better is the algorithm. Memory – To execute a program, computer system takes some amount of memory space. The lesser is the memory required, the better is the algorithm. Accuracy – Multiple algorithms may provide suitable or correct solutions to a given problem, some of these may provide more accurate results than others, and such algorithms may be suitable. Example Write an algorithm to print „Good Morning” Step 1: Start Step 2: Print “Good Morning” Step 3: Stop
  • 7. BUILDING BLOCKS OF ALGORITHMS (statements, state, control flow, functions) Algorithms can be constructed from basic building blocks namely, sequence, selection and iteration. Statements: Statement is a single action in a computer. In a computer statements might include some of the following actions Ø input data-information given to the program Ø process data-perform operation on a given input Ø output data-processed result State: Transition from one process to another process under specified condition with in a time is called state. Control flow: The process of executing the individual statements in a given order is called control flow. The control can be executed in three ways 1. sequence 2. selection 3. iteration
  • 8. Sequence: All the instructions are executed one after another is called sequence execution. Example: Add two numbers: Step 1: Start Step 2: get a,b Step 3: calculate c=a+b Step 4: Display c Step 5: Stop
  • 9. Selection: A selection statement causes the program control to be transferred to a specific part of the program based upon the condition. If the conditional test is true, one part of the program will be executed, otherwise it will execute the other part of the program. Example Write an algorithm to check whether he is eligible to vote? Step 1: Start Step 2: Get age Step 3: if age >= 18 print “Eligible to vote” Step 4: else print “Not eligible to vote” Step 6: Stop
  • 10. Iteration: In some programs, certain set of statements are executed again and again based upon conditional test. i.e. executed more than one time. This type of execution is called looping or iteration. Example Write an algorithm to print all natural numbers up to n Step 1: Start Step 2: get n value. Step 3: initialize i=1 Step 4: if (i<=n) go to step 5 else go to step 7 Step 5: Print i value and increment i value by 1 Step 6: go to step 4 Step 7: Stop
  • 11. Functions: v Function is a sub program which consists of block of code(set of instructions) that performs a particular task. v For complex problems, the problem is been divided into smaller and simpler tasks during algorithm design. Benefits of Using Functions v Reduction in line of code v code reuse v Better readability v Information hiding v Easy to debug and test v Improved maintainability
  • 12. Example: Algorithm for addition of two numbers using function Main function() Step 1: Start Step 2: Call the function add() Step 3: Stop sub function add() Step 1: Function start Step 2: Get a, b Values Step 3: add c=a+b Step 4: Print c Step 5: Return
  • 13. NOTATIONS FLOW CHART • Flow chart is defined as graphical representation of the logic for problem solving. • The purpose of flowchart is making the logic of the program clear in a visual representation.
  • 14. Rules for drawing a flowchart 1. The flowchart should be clear, neat and easy to follow. 2. The flowchart must have a logical start and finish. 3. Only one flow line should come out from a process symbol. 4. Only one flow line should enter a decision symbol. However, two or three flow lines may leave the decision symbol.
  • 15. 5. Only one flow line is used with a terminal symbol. 6. Within standard symbols, write briefly and precisely. 7. Intersection of flow lines should be avoided.
  • 16. Advantages of flowchart: 1. Communication: - Flowcharts are better way of communicating the logic of a system to all concerned. 2. Effective analysis: - With the help of flowchart, problem can be analysed in more effective way. 3. Proper documentation: - Program flowcharts serve as a good program documentation, which is needed for various purposes. 4. Efficient Coding: - The flowcharts act as a guide or blueprint during the systems analysis and program development phase. 5. Proper Debugging: - The flowchart helps in debugging process. 6. Efficient Program Maintenance: - The maintenance of operating program becomes easy with the help of flowchart. It helps the programmer to put efforts more efficiently on that part.
  • 17. Disadvantages of flow chart: 1. Complex logic: - Sometimes, the program logic is quite complicated. In that case, flowchart becomes complex and clumsy. 2. Alterations and Modifications: - If alterations are required the flowchart may require re-drawing completely. 3. Reproduction: - As the flowchart symbols cannot be typed, reproduction of flowchart becomes a problem. 4. Cost: For large application the time and cost of flowchart drawing becomes costly.
  • 18. STEP1: START STEP2: Get n value STEP 3: if n % 2==0 then GOTO STEP 4 ,otherwise GOTO STEP 5 STEO4: PRINT N is EVEN number STEP 5: PRINT N is ODD number STEP6: STOP
  • 19. PSEUDO CODE: ■ Pseudo code consists of short, readable and formally styled English languages used for explain an algorithm. ■ It does not include details like variable declaration, subroutines. ■ It is easier to understand for the programmer or non programmer to understand ■ the general working of the program, because it is not based on any programming language. ■ It gives us the sketch of the program before actual coding. ■ It is not a machine readable ■ Pseudo code can’t be compiled and executed. ■ There is no standard syntax for pseudo code.
  • 20. Guidelines for writing pseudo code: ■ Write one statement per line ■ Capitalize initial keyword ■ Indent to hierarchy ■ End multiline structure ■ Keep statements language independent
  • 21. Common keywords used in pseudocode The following gives common keywords used in pseudocodes. 1. //: This keyword used to represent a comment. 2. BEGIN,END: Begin is the first statement and end is the last statement. 3. INPUT, GET, READ: The keyword is used to inputting data. 4. COMPUTE, CALCULATE: used for calculation of the result of the given expression. 5. ADD, SUBTRACT, INITIALIZE used for addition, subtraction and initialization. 6. OUTPUT, PRINT, DISPLAY: It is used to display the output of the program. 7. IF, ELSE, ENDIF: used to make decision. 8. WHILE, ENDWHILE: used for iterative statements. 9. FOR, ENDFOR: Another iterative incremented/decremented tested automatically.
  • 23. EVEN/ODD Num=int(“Enter any value”) IF(num%2==0) PRINT(“ num even number”) ELSE PRINT (“num odd number”)
  • 24. Advantages: ■ Pseudo is independent of any language; it can be used by most programmers. ■ It is easy to translate pseudo code into a programming language. ■ It can be easily modified as compared to flowchart. ■ Converting a pseudo code to programming language is very easy as compared with converting a flowchart to programming language.
  • 25. Disadvantages: ■ It does not provide visual representation of the program’s logic. ■ There are no accepted standards for writing pseudo codes. ■ It cannot be compiled nor executed. ■ For a beginner, It is more difficult to follow the logic or write pseudo code as compared to flowchart.
  • 26. Example: Addition of two numbers: BEGIN GET a,b ADD c=a+b PRINT c END