SlideShare a Scribd company logo
1 of 49
PROBLEM-SOLVING
USING COMPUTERS
- CHAPTER 1
PROBLEM
SOLVING
USING
COMPUTERS
INTRODUCTION
Problem-solving is transforming the description of a
problem into a solution by using our knowledge of the
problem domain and relying on our ability to select and
use appropriate problem-solving strategies, techniques,
and tools.
When we write a program, we are actually writing
instructions for the computer to solve something for us.
A COMPUTER IS A TOOL TO SOLVE A PROBLEM
PROGRAMMING IS A PROBLEM-SOLVING ACTIVITY
PROBLEM DEFINITION (Problem statement)
1
PROBLEM ANALYSIS (Identify Input, Output,
Constraints, Formulas to be used (if any)
2
COMPILATION & EXECUTION
4 CODING
3
DEBUGGING & TESTING
5
DOCUMENTATION
6
STEPS IN PROBLEM-
SOLVING
7
PROBLEM APPROACH (Algorithm, Pseudo
code, Flowchart)
A set of finite rules or
instructions to be followed in
calculations or other problem-
solving operations
ALGORITHM
Write down the steps for making peanut butter and jelly sandwich
TASK
Ingredients - Bread, Peanut butter, Jelly
Step 1: Start preparation
Step 2: Take 2 slices of bread.
Step 3: Apply peanut butter on one side of a slice.
Step 3: Apply jelly on one side of the other slice.
Step 4: Press both slices of bread together.
Step 5: Serve
CONCLUSION: Algorithm is step-wise idea of what is to be done to
get a desired output from the given input
Algorithm to add 3 numbers and print their sum
EXAMPLE
Variables - n1 | n2 | n3 | sum
START
Declare 3 integer variables n1, n2 and n3.
Take the three numbers, to be added, as
inputs in variables n1, n2, and n3 respectively.
Declare an integer variable sum to store the
resultant sum of the 3 numbers.
Add the 3 numbers and store the result in the
variable sum. (n1 + n2 + n3)
Print the value of the variable sum
END
1.
2.
3.
4.
5.
6.
7.
It should terminate after a finite time.
It should produce at least one output.
It should take zero or more input.
It should be deterministic means giving the same
output for the same input case.
Every step in the algorithm must be effective i.e.
every step should do some work.
PROPERTIES OF ALGORITHM
CHECK FOR LANGUAGE INDEPENDENCY
// C PROGRAM
#include <stdio.h>
int main()
{
int n1, n2, n3;
scanf("%d %d %d",&n1,&n2,&n3);
int sum;
sum = n1+n2+n3;
printf("%d",sum);
return 0;
}
// PYTHON PROGRAM
if __name__ == "__main__":
n1 = n2 = n3 = 0
n1 = int(input())
n2 = int(input())
n3 = int(input())
sum = 0
sum = n1+n2+n3
print(sum)
// PYTHON PROGRAM
if __name__ == "__main__":
n1 = int(input())
n2 = int(input())
n3 = int(input())
sum = n1+n2+n3
print(sum)
FLOWCHART
PSEUDO-CODE
HOW TO EXPRESS AN ALGORITHM?
FLOWCHART
A flowchart is a graphical representation of an
algorithm. Programmers often use it as a program-
planning tool to solve a problem.
It makes use of symbols that are connected among them
to indicate the flow of information and processing.
The process of drawing a flowchart for an algorithm is
known as “flowcharting”.
Draw a flowchart to add 3 numbers and print their sum
EXAMPLE
Refer the below algorithm
START
Declare 3 integer variables n1, n2 and n3.
Take the three numbers, to be added, as
inputs in variables n1, n2, and n3 respectively.
Declare an integer variable sum to store the
resultant sum of the 3 numbers.
Add the 3 numbers and store the result in the
variable sum. (n1 + n2 + n3)
Print the value of the variable sum
END
1.
2.
3.
4.
5.
6.
7.
PSEUDO-CODE
The pseudocode is an informal way of writing a
program for better human understanding.
It is written in simple English, making the complex
program easier to understand.
Pseudocode cannot be compiled or interpreted.
It is a methodology that allows the programmer to
represent the implementation of an algorithm.
Write only one statement per line
Capitalize initial keyword
Indent to show hierarchy
End multiline structures
Keep statements language independent
It gives us the sketch of the program before actual
coding
Use the naming domain of the problem, not that of
the implementation. For instance: “Append the last
name to the first name” instead of “name = first+
last.”
Keep it simple, concise and readable.
RULES OF PSEUDO-CODE
EXAMPLE 2: WRITE THE PSEUDO CODE TO FIND THE GREATEST OF TWO NUMBERS
BEGIN
READ A,B
IF (A>B) THEN
DISPLAY a is greater
ELSE
DISPLAY b is greater
END IF
END
BRUTE FORCE ALGORITHM
Brute Force Algorithms are exactly what they sound like –
straightforward methods of solving a problem that relies on
sheer computing power and trying every possibility rather
than advanced techniques to improve efficiency.
Brute Force algorithm is a typical problem-solving
technique where the possible solution for a problem is
uncovered by checking each answer one by one, by
determining whether the result satisfies the statement of a
problem or not.
Bubble sort is one of the easiest and brute force sorting
algorithm.
RECURSIVE ALGORITHM
A recursive algorithm calls itself with smaller input values
and returns the result for the current input by carrying out
basic operations on the returned value for the smaller
input.
A recursive algorithm is an algorithm that calls itself with
"smaller (or simpler)" input values, and which obtains the
result for the current input by applying simple operations
to the returned value for the smaller (or simpler) input.
Generation of factorial, Fibonacci number series are
examples of recursive algorithms.
GREEDY ALGORITHM
Greedy is an algorithmic paradigm that builds up a solution
piece by piece, always choosing the next piece that offers
the most obvious and immediate benefit. So the problems
where choosing locally optimal also leads to the global
solution being the best fit for Greedy.
For example)
Fractional Knapsack Problem
DYNAMIC ALGORITHM
Dynamic Programming is a technique in computer
programming that helps to efficiently solve a class of
problems that have overlapping subproblems and optimal
substructure properties.
The main use of dynamic programming is to solve
optimization problems. Here, optimization problems mean
that when we are trying to find out the minimum or the
maximum solution to a problem. Dynamic programming
guarantees finding the optimal solution to a problem if the
solution exists.
A top-down approach is about breaking down a system into the
subsystems that make it up. The process can be repeated to
break down subsystems into low-level elements like classes and
methods. This approach can be applied to all levels from high-
level system architecture to low-level functionality
implementation, just to remember to start from the top. It
doesn’t necessarily always be the absolute top.
Top-Down Model is followed by structural programming
languages like C, Fortran etc.
TOP DOWN APPROACH
In this design, individual parts of the system are specified in
detail. The parts are linked to form larger components, which
are in turn linked until a complete system is formed.
Object-oriented language such as C++, Python, or Java uses a
bottom-up approach where each object is identified first.
BOTTOM UP APPROACH
So simple. It's because you first defines a class and it's functions. Then you initialise
an object of that class and calls functions as per the need. Now, though process looks
like to-bottom but the execution takes place in bottom-up approach. While executing,
execution flow find object initialisation first and then it looks up for declared class
and then functions.
WHY DO OOPS FOLLOW THE BOTTOM-UP APPROACH?
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
obj1 = Person("Harry", 36)
obj2 = Person("Styles", 35)
print(obj1.name)
print(obj1.age)
print("------")
print(obj2.name)
print(obj2.age)
IS PYTHON AN OBJECT-ORIENTED PROGRAMMING
LANGUAGE?
Python is both procedural and has object-oriented features, as well as some aspects of
functional programming. That is what is meant when one says that Python is a multi-
paradigm.
Python are multi-paradigm, you can write programs or libraries that are largely
procedural, object-oriented, or functional in all of these languages. It depends on
what you mean by functional. Python does have some features of a functional
language.
OOP's concepts like, Classes,Encapsulation,Polymorphism, Inheritance etc.. in Python
makes it as a object oriented programming language.
IS PYTHON AN OBJECT-ORIENTED PROGRAMMING
LANGUAGE?
TIME COMPLEXITY
SPACE COMPLEXITY
MEASURES FOR THE EFFICIENCY OF AN ALGORITHM
SWAP TWO NUMBERS - METHOD 1
(Using third variable)
x = 10
y = 50
# Swapping of two variables
# Using third variable
temp = x
x = y
y = temp
print("Value of x:", x)
print("Value of y:", y)
x = 10
y = 50
# Swapping of two variables
# without using third variable
x, y = y, x
print("Value of x:", x)
print("Value of y:", y)
SWAP TWO NUMBERS - METHOD 2
(Using comma method)
NOW IT'S TIME TO
PRACTICE
PROBLEM STATEMENT - Airport security officials have
confiscated several item of the passengers at the security check
point. All the items have been dumped into a huge box (array). Each
item possesses a certain amount of risk[0,1,2]. Here, the risk
severity of the items represent an array[] of N number of integer
values. The task here is to sort the items based on their levels of
risk in the array. The risk values range from 0 to 2.
Example :
Input :
7 -> Value of N
[1,0,2,0,1,0,2]-> Element of arr[0] to arr[N-1], while input each
element is separated by a new line.
Output :
0 0 0 1 1 2 2 -> Element after sorting based on risk severity
Explanation:
In the above example, the input is an array of size N consisting of
only 0’s, 1’s, and 2s. The output is a sorted array from 0 to 2 based
on risk severity.
mins
n = int(input())
arr = []
for i in range(n):
arr.append(int(input()))
arr.sort()
for i in range(n):
print(arr[i], end = " ")
PSEUDOCODE -
BEGIN
READ n
INITIALIZE list arr[]
FOR i <-- 0 to n-1
APPEND elements to the list
SORT the array list arr[]
FOR i <-- 0 to n-1
PRINT elements of the array list
END
Thank you!

More Related Content

Similar to Problem solving using computers - Chapter 1

DAA-Unit1.pptx
DAA-Unit1.pptxDAA-Unit1.pptx
DAA-Unit1.pptxNishaS88
 
Algorithmsandflowcharts1
Algorithmsandflowcharts1Algorithmsandflowcharts1
Algorithmsandflowcharts1rajnidhiman
 
Lecture 01-2.ppt
Lecture 01-2.pptLecture 01-2.ppt
Lecture 01-2.pptRaoHamza24
 
As Level Computer Science Book -2
As Level Computer Science  Book -2As Level Computer Science  Book -2
As Level Computer Science Book -2DIGDARSHAN KUNWAR
 
01 Algorithms And Flowcharts.ppt
01 Algorithms And Flowcharts.ppt01 Algorithms And Flowcharts.ppt
01 Algorithms And Flowcharts.pptFerdieBalang
 
CP4151 ADSA unit1 Advanced Data Structures and Algorithms
CP4151 ADSA unit1 Advanced Data Structures and AlgorithmsCP4151 ADSA unit1 Advanced Data Structures and Algorithms
CP4151 ADSA unit1 Advanced Data Structures and AlgorithmsSheba41
 
maXbox Starter 36 Software Testing
maXbox Starter 36 Software TestingmaXbox Starter 36 Software Testing
maXbox Starter 36 Software TestingMax Kleiner
 
Jeremiah Yancy - Objectives for Software design and testing
Jeremiah Yancy - Objectives for Software design and testingJeremiah Yancy - Objectives for Software design and testing
Jeremiah Yancy - Objectives for Software design and testingJeremiah Yancy
 
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
TIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMSTIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMS
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMSTanya Makkar
 
Analysis and Design of Algorithms notes
Analysis and Design of Algorithms  notesAnalysis and Design of Algorithms  notes
Analysis and Design of Algorithms notesProf. Dr. K. Adisesha
 
VCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxVCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxskilljiolms
 
Java conceptual learning material
Java conceptual learning materialJava conceptual learning material
Java conceptual learning materialArthyR3
 

Similar to Problem solving using computers - Chapter 1 (20)

DATA STRUCTURE.pdf
DATA STRUCTURE.pdfDATA STRUCTURE.pdf
DATA STRUCTURE.pdf
 
DATA STRUCTURE
DATA STRUCTUREDATA STRUCTURE
DATA STRUCTURE
 
Algorithmsandflowcharts1
Algorithmsandflowcharts1Algorithmsandflowcharts1
Algorithmsandflowcharts1
 
DAA-Unit1.pptx
DAA-Unit1.pptxDAA-Unit1.pptx
DAA-Unit1.pptx
 
Algorithmsandflowcharts1
Algorithmsandflowcharts1Algorithmsandflowcharts1
Algorithmsandflowcharts1
 
Algorithmsandflowcharts1
Algorithmsandflowcharts1Algorithmsandflowcharts1
Algorithmsandflowcharts1
 
UNIT-2-PPTS-DAA.ppt
UNIT-2-PPTS-DAA.pptUNIT-2-PPTS-DAA.ppt
UNIT-2-PPTS-DAA.ppt
 
Lecture 01-2.ppt
Lecture 01-2.pptLecture 01-2.ppt
Lecture 01-2.ppt
 
As Level Computer Science Book -2
As Level Computer Science  Book -2As Level Computer Science  Book -2
As Level Computer Science Book -2
 
01 Algorithms And Flowcharts.ppt
01 Algorithms And Flowcharts.ppt01 Algorithms And Flowcharts.ppt
01 Algorithms And Flowcharts.ppt
 
Create and analyse programs
Create and analyse programsCreate and analyse programs
Create and analyse programs
 
Dutch PHP Conference 2013: Distilled
Dutch PHP Conference 2013: DistilledDutch PHP Conference 2013: Distilled
Dutch PHP Conference 2013: Distilled
 
ALGO.ppt
ALGO.pptALGO.ppt
ALGO.ppt
 
CP4151 ADSA unit1 Advanced Data Structures and Algorithms
CP4151 ADSA unit1 Advanced Data Structures and AlgorithmsCP4151 ADSA unit1 Advanced Data Structures and Algorithms
CP4151 ADSA unit1 Advanced Data Structures and Algorithms
 
maXbox Starter 36 Software Testing
maXbox Starter 36 Software TestingmaXbox Starter 36 Software Testing
maXbox Starter 36 Software Testing
 
Jeremiah Yancy - Objectives for Software design and testing
Jeremiah Yancy - Objectives for Software design and testingJeremiah Yancy - Objectives for Software design and testing
Jeremiah Yancy - Objectives for Software design and testing
 
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
TIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMSTIME EXECUTION   OF  DIFFERENT SORTED ALGORITHMS
TIME EXECUTION OF DIFFERENT SORTED ALGORITHMS
 
Analysis and Design of Algorithms notes
Analysis and Design of Algorithms  notesAnalysis and Design of Algorithms  notes
Analysis and Design of Algorithms notes
 
VCE Unit 01 (2).pptx
VCE Unit 01 (2).pptxVCE Unit 01 (2).pptx
VCE Unit 01 (2).pptx
 
Java conceptual learning material
Java conceptual learning materialJava conceptual learning material
Java conceptual learning material
 

More from To Sum It Up

Prompt Engineering | Beginner's Guide - For You
Prompt Engineering | Beginner's Guide - For YouPrompt Engineering | Beginner's Guide - For You
Prompt Engineering | Beginner's Guide - For YouTo Sum It Up
 
Natural Language Processing (NLP) | Basics
Natural Language Processing (NLP) | BasicsNatural Language Processing (NLP) | Basics
Natural Language Processing (NLP) | BasicsTo Sum It Up
 
It's Machine Learning Basics -- For You!
It's Machine Learning Basics -- For You!It's Machine Learning Basics -- For You!
It's Machine Learning Basics -- For You!To Sum It Up
 
Polymorphism in Python
Polymorphism in PythonPolymorphism in Python
Polymorphism in PythonTo Sum It Up
 
Web API - Overview
Web API - OverviewWeb API - Overview
Web API - OverviewTo Sum It Up
 
User story mapping
User story mappingUser story mapping
User story mappingTo Sum It Up
 
Quality Circle | Case Study on Self Esteem | Team Opus Geeks.pdf
Quality Circle | Case Study on Self Esteem | Team Opus Geeks.pdfQuality Circle | Case Study on Self Esteem | Team Opus Geeks.pdf
Quality Circle | Case Study on Self Esteem | Team Opus Geeks.pdfTo Sum It Up
 
Multimedia Content and Content Acquisition
Multimedia Content and Content AcquisitionMultimedia Content and Content Acquisition
Multimedia Content and Content AcquisitionTo Sum It Up
 
PHP Arrays_Introduction
PHP Arrays_IntroductionPHP Arrays_Introduction
PHP Arrays_IntroductionTo Sum It Up
 
System Calls - Introduction
System Calls - IntroductionSystem Calls - Introduction
System Calls - IntroductionTo Sum It Up
 
Programming The Basic Computer
Programming The Basic ComputerProgramming The Basic Computer
Programming The Basic ComputerTo Sum It Up
 
Ozone in wastewater treatment
Ozone in wastewater treatmentOzone in wastewater treatment
Ozone in wastewater treatmentTo Sum It Up
 

More from To Sum It Up (19)

Prompt Engineering | Beginner's Guide - For You
Prompt Engineering | Beginner's Guide - For YouPrompt Engineering | Beginner's Guide - For You
Prompt Engineering | Beginner's Guide - For You
 
Natural Language Processing (NLP) | Basics
Natural Language Processing (NLP) | BasicsNatural Language Processing (NLP) | Basics
Natural Language Processing (NLP) | Basics
 
It's Machine Learning Basics -- For You!
It's Machine Learning Basics -- For You!It's Machine Learning Basics -- For You!
It's Machine Learning Basics -- For You!
 
Polymorphism in Python
Polymorphism in PythonPolymorphism in Python
Polymorphism in Python
 
DSA Question Bank
DSA Question BankDSA Question Bank
DSA Question Bank
 
Web API - Overview
Web API - OverviewWeb API - Overview
Web API - Overview
 
CSS Overview
CSS OverviewCSS Overview
CSS Overview
 
HTML Overview
HTML OverviewHTML Overview
HTML Overview
 
EM Algorithm
EM AlgorithmEM Algorithm
EM Algorithm
 
User story mapping
User story mappingUser story mapping
User story mapping
 
User stories
User storiesUser stories
User stories
 
Quality Circle | Case Study on Self Esteem | Team Opus Geeks.pdf
Quality Circle | Case Study on Self Esteem | Team Opus Geeks.pdfQuality Circle | Case Study on Self Esteem | Team Opus Geeks.pdf
Quality Circle | Case Study on Self Esteem | Team Opus Geeks.pdf
 
Multimedia Content and Content Acquisition
Multimedia Content and Content AcquisitionMultimedia Content and Content Acquisition
Multimedia Content and Content Acquisition
 
PHP Arrays_Introduction
PHP Arrays_IntroductionPHP Arrays_Introduction
PHP Arrays_Introduction
 
System Calls - Introduction
System Calls - IntroductionSystem Calls - Introduction
System Calls - Introduction
 
Leadership
LeadershipLeadership
Leadership
 
Programming The Basic Computer
Programming The Basic ComputerProgramming The Basic Computer
Programming The Basic Computer
 
SQL | DML
SQL | DMLSQL | DML
SQL | DML
 
Ozone in wastewater treatment
Ozone in wastewater treatmentOzone in wastewater treatment
Ozone in wastewater treatment
 

Recently uploaded

Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learningmisbanausheenparvam
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 

Recently uploaded (20)

🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
chaitra-1.pptx fake news detection using machine learning
chaitra-1.pptx  fake news detection using machine learningchaitra-1.pptx  fake news detection using machine learning
chaitra-1.pptx fake news detection using machine learning
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 

Problem solving using computers - Chapter 1

  • 1. PROBLEM-SOLVING USING COMPUTERS - CHAPTER 1 PROBLEM SOLVING USING COMPUTERS
  • 2. INTRODUCTION Problem-solving is transforming the description of a problem into a solution by using our knowledge of the problem domain and relying on our ability to select and use appropriate problem-solving strategies, techniques, and tools. When we write a program, we are actually writing instructions for the computer to solve something for us. A COMPUTER IS A TOOL TO SOLVE A PROBLEM PROGRAMMING IS A PROBLEM-SOLVING ACTIVITY
  • 3. PROBLEM DEFINITION (Problem statement) 1 PROBLEM ANALYSIS (Identify Input, Output, Constraints, Formulas to be used (if any) 2 COMPILATION & EXECUTION 4 CODING 3 DEBUGGING & TESTING 5 DOCUMENTATION 6 STEPS IN PROBLEM- SOLVING 7 PROBLEM APPROACH (Algorithm, Pseudo code, Flowchart)
  • 4. A set of finite rules or instructions to be followed in calculations or other problem- solving operations ALGORITHM
  • 5. Write down the steps for making peanut butter and jelly sandwich TASK Ingredients - Bread, Peanut butter, Jelly
  • 6. Step 1: Start preparation Step 2: Take 2 slices of bread. Step 3: Apply peanut butter on one side of a slice. Step 3: Apply jelly on one side of the other slice. Step 4: Press both slices of bread together. Step 5: Serve CONCLUSION: Algorithm is step-wise idea of what is to be done to get a desired output from the given input
  • 7. Algorithm to add 3 numbers and print their sum EXAMPLE Variables - n1 | n2 | n3 | sum
  • 8. START Declare 3 integer variables n1, n2 and n3. Take the three numbers, to be added, as inputs in variables n1, n2, and n3 respectively. Declare an integer variable sum to store the resultant sum of the 3 numbers. Add the 3 numbers and store the result in the variable sum. (n1 + n2 + n3) Print the value of the variable sum END 1. 2. 3. 4. 5. 6. 7.
  • 9. It should terminate after a finite time. It should produce at least one output. It should take zero or more input. It should be deterministic means giving the same output for the same input case. Every step in the algorithm must be effective i.e. every step should do some work. PROPERTIES OF ALGORITHM
  • 10.
  • 11. CHECK FOR LANGUAGE INDEPENDENCY // C PROGRAM #include <stdio.h> int main() { int n1, n2, n3; scanf("%d %d %d",&n1,&n2,&n3); int sum; sum = n1+n2+n3; printf("%d",sum); return 0; } // PYTHON PROGRAM if __name__ == "__main__": n1 = n2 = n3 = 0 n1 = int(input()) n2 = int(input()) n3 = int(input()) sum = 0 sum = n1+n2+n3 print(sum) // PYTHON PROGRAM if __name__ == "__main__": n1 = int(input()) n2 = int(input()) n3 = int(input()) sum = n1+n2+n3 print(sum)
  • 13. FLOWCHART A flowchart is a graphical representation of an algorithm. Programmers often use it as a program- planning tool to solve a problem. It makes use of symbols that are connected among them to indicate the flow of information and processing. The process of drawing a flowchart for an algorithm is known as “flowcharting”.
  • 14.
  • 15.
  • 16. Draw a flowchart to add 3 numbers and print their sum EXAMPLE Refer the below algorithm
  • 17. START Declare 3 integer variables n1, n2 and n3. Take the three numbers, to be added, as inputs in variables n1, n2, and n3 respectively. Declare an integer variable sum to store the resultant sum of the 3 numbers. Add the 3 numbers and store the result in the variable sum. (n1 + n2 + n3) Print the value of the variable sum END 1. 2. 3. 4. 5. 6. 7.
  • 18.
  • 19. PSEUDO-CODE The pseudocode is an informal way of writing a program for better human understanding. It is written in simple English, making the complex program easier to understand. Pseudocode cannot be compiled or interpreted. It is a methodology that allows the programmer to represent the implementation of an algorithm.
  • 20.
  • 21.
  • 22. Write only one statement per line Capitalize initial keyword Indent to show hierarchy End multiline structures Keep statements language independent It gives us the sketch of the program before actual coding Use the naming domain of the problem, not that of the implementation. For instance: “Append the last name to the first name” instead of “name = first+ last.” Keep it simple, concise and readable. RULES OF PSEUDO-CODE
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29. EXAMPLE 2: WRITE THE PSEUDO CODE TO FIND THE GREATEST OF TWO NUMBERS BEGIN READ A,B IF (A>B) THEN DISPLAY a is greater ELSE DISPLAY b is greater END IF END
  • 30.
  • 31. BRUTE FORCE ALGORITHM Brute Force Algorithms are exactly what they sound like – straightforward methods of solving a problem that relies on sheer computing power and trying every possibility rather than advanced techniques to improve efficiency. Brute Force algorithm is a typical problem-solving technique where the possible solution for a problem is uncovered by checking each answer one by one, by determining whether the result satisfies the statement of a problem or not. Bubble sort is one of the easiest and brute force sorting algorithm.
  • 32. RECURSIVE ALGORITHM A recursive algorithm calls itself with smaller input values and returns the result for the current input by carrying out basic operations on the returned value for the smaller input. A recursive algorithm is an algorithm that calls itself with "smaller (or simpler)" input values, and which obtains the result for the current input by applying simple operations to the returned value for the smaller (or simpler) input. Generation of factorial, Fibonacci number series are examples of recursive algorithms.
  • 33. GREEDY ALGORITHM Greedy is an algorithmic paradigm that builds up a solution piece by piece, always choosing the next piece that offers the most obvious and immediate benefit. So the problems where choosing locally optimal also leads to the global solution being the best fit for Greedy. For example) Fractional Knapsack Problem
  • 34. DYNAMIC ALGORITHM Dynamic Programming is a technique in computer programming that helps to efficiently solve a class of problems that have overlapping subproblems and optimal substructure properties. The main use of dynamic programming is to solve optimization problems. Here, optimization problems mean that when we are trying to find out the minimum or the maximum solution to a problem. Dynamic programming guarantees finding the optimal solution to a problem if the solution exists.
  • 35. A top-down approach is about breaking down a system into the subsystems that make it up. The process can be repeated to break down subsystems into low-level elements like classes and methods. This approach can be applied to all levels from high- level system architecture to low-level functionality implementation, just to remember to start from the top. It doesn’t necessarily always be the absolute top. Top-Down Model is followed by structural programming languages like C, Fortran etc. TOP DOWN APPROACH
  • 36.
  • 37. In this design, individual parts of the system are specified in detail. The parts are linked to form larger components, which are in turn linked until a complete system is formed. Object-oriented language such as C++, Python, or Java uses a bottom-up approach where each object is identified first. BOTTOM UP APPROACH
  • 38.
  • 39. So simple. It's because you first defines a class and it's functions. Then you initialise an object of that class and calls functions as per the need. Now, though process looks like to-bottom but the execution takes place in bottom-up approach. While executing, execution flow find object initialisation first and then it looks up for declared class and then functions. WHY DO OOPS FOLLOW THE BOTTOM-UP APPROACH?
  • 40. class Person: def __init__(self, name, age): self.name = name self.age = age obj1 = Person("Harry", 36) obj2 = Person("Styles", 35) print(obj1.name) print(obj1.age) print("------") print(obj2.name) print(obj2.age)
  • 41. IS PYTHON AN OBJECT-ORIENTED PROGRAMMING LANGUAGE?
  • 42. Python is both procedural and has object-oriented features, as well as some aspects of functional programming. That is what is meant when one says that Python is a multi- paradigm. Python are multi-paradigm, you can write programs or libraries that are largely procedural, object-oriented, or functional in all of these languages. It depends on what you mean by functional. Python does have some features of a functional language. OOP's concepts like, Classes,Encapsulation,Polymorphism, Inheritance etc.. in Python makes it as a object oriented programming language. IS PYTHON AN OBJECT-ORIENTED PROGRAMMING LANGUAGE?
  • 43. TIME COMPLEXITY SPACE COMPLEXITY MEASURES FOR THE EFFICIENCY OF AN ALGORITHM
  • 44. SWAP TWO NUMBERS - METHOD 1 (Using third variable) x = 10 y = 50 # Swapping of two variables # Using third variable temp = x x = y y = temp print("Value of x:", x) print("Value of y:", y) x = 10 y = 50 # Swapping of two variables # without using third variable x, y = y, x print("Value of x:", x) print("Value of y:", y) SWAP TWO NUMBERS - METHOD 2 (Using comma method)
  • 45. NOW IT'S TIME TO PRACTICE
  • 46. PROBLEM STATEMENT - Airport security officials have confiscated several item of the passengers at the security check point. All the items have been dumped into a huge box (array). Each item possesses a certain amount of risk[0,1,2]. Here, the risk severity of the items represent an array[] of N number of integer values. The task here is to sort the items based on their levels of risk in the array. The risk values range from 0 to 2. Example : Input : 7 -> Value of N [1,0,2,0,1,0,2]-> Element of arr[0] to arr[N-1], while input each element is separated by a new line. Output : 0 0 0 1 1 2 2 -> Element after sorting based on risk severity Explanation: In the above example, the input is an array of size N consisting of only 0’s, 1’s, and 2s. The output is a sorted array from 0 to 2 based on risk severity.
  • 47. mins
  • 48. n = int(input()) arr = [] for i in range(n): arr.append(int(input())) arr.sort() for i in range(n): print(arr[i], end = " ") PSEUDOCODE - BEGIN READ n INITIALIZE list arr[] FOR i <-- 0 to n-1 APPEND elements to the list SORT the array list arr[] FOR i <-- 0 to n-1 PRINT elements of the array list END