SlideShare a Scribd company logo
2
Most read
3
Most read
6
Most read
Problem solving using computers – Unit 1
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-SOLVING ASPECT –
Steps in problem solving –
1. PROBLEM DEFINITION (Problem statement)
2. PROBLEM ANALYSIS (Identify Input, Output, Constraints, Formulas to be used (if
any)
3. PROBLEM APPROACH (Algorithm, Pseudo code, Flowchart)
4. CODING
5. COMPILATION & EXECUTION
6. DEBUGGING & TESTING
7. DOCUMENTATION
Algorithm – A set of finite rules or instructions to be followed in calculations or other problem-
solving operations.
Example –
Algorithm to add 3 numbers and print their sum (Variables - n1 | n2 | n3 | sum)
1. START
2. Declare 3 integer variables n1, n2 and n3.
3. Take the three numbers, to be added, as inputs in variables n1, n2, and n3 respectively.
4. Declare an integer variable sum to store the resultant sum of the 3 numbers.
5. Add the 3 numbers and store the result in the variable sum. (n1 + n2 + n3)
6. Print the value of the variable sum
7. END
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)
How to express an Algorithm?
• FLOWCHART
• PSEUDO-CODE
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.” A flowchart can be helpful for both writing
programs and explaining the program to others.
When to use a flowchart?
1. To develop understanding of how a process is done
2. To study a process for improvement
3. To communicate to others how a process is done
4. When better communication is needed between people involved with the same process
5. To document a process
6. When planning a project
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.
RULES OF PSEUDO-CODE
• 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.
Example:
Write a 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
Top-down design approach –
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.
EXAMPLE –
// User-defined function
void add(int a, int b)
{
printf("%d + %d = %d", a+b);
}
// Driver code
int main()
{
int a,b;
scanf("%d%d", &a, &b);
add(a,b); //Function call
return 0;
}
The function call is the main task, which calls the subtask that has the implementation. It is
noted that the main() function is the top-most implementation and execution zone.
Program testing –
Program testing is the process of executing a program with the intent of finding errors. A good
test is one that has a high probability of finding an error. Program testing cannot show the
absence of errors. It can only show if errors are present.
Time Complexity –
The Time Complexity of an algorithm/code is not equal to the actual time required to execute
a particular code, but the number of times a statement executes. And, there exists a relation
between the input data size (n) and the number of operations performed (N) with respect to
time. This relation is denoted as Order of growth in Time complexity and given notation O[n]
where O is the order of growth and n is the length of the input. It is also called as ‘Big O
Notation’
There are five types of Time complexity Cases:
• Constant Time Complexity - O(1)
• Logarithmic Time Complexity - O(log n)
• Linear Time Complexity - O(n)
• O(n log n) Time Complexity
• Quadratic Time Complexity - O(n2)
Loops and Time complexity –
1. O(N)
for(i=0; i < N; i++){
some O(1) expressions
}
The Time Complexity of a loop is considered as O(n) if the loop variables are
incremented/decremented by a constant amount.
2. O(N^2)
for(i=0; i < N; i++) {
for(j=0; j < N;j++){
some O(1) expressions
}
}
The time complexity is defined as an algorithm whose performance is directly
proportional to the squared size of the input data, as in nested loops it is equal to the
number of times the innermost statement is executed.
3. O(log N)
for (int i = 1; i <= N; i *= c) {
// some O(1) expressions
}
for (int i = N; i > 0; i /= c) {
// some O(1) expressions
}
The time Complexity of a loop is considered as O(log n) if the loop variables are
divided/multiplied by a constant amount. And also for recursive calls in the recursive
function, the time Complexity is considered as O(log n).
Space complexity –
The space Complexity of an algorithm is the total space taken by the algorithm with respect to
the input size. Space complexity includes both Auxiliary space and space used by input.
Space Complexity = Auxiliary Space + Space used for input values
EXCHANGING/SWAPPING OF VARIABLES
Problem statement – Given two variables x and y, exchange the values assigned to them.
METHOD – 1 (Using third variable)
Code
x = int(input("Enter the value of x: "))
y = int(input("Enter the value of y: "))
# Swap using third variable
temp = x
x = y
y = temp
print("nAfter exchanging - ")
print("Value of x:", x)
print("Value of y:", y)
Output –
Enter the value of x: 5
Enter the value of y: 6
After exchanging -
Value of x: 6
Value of y: 5
METHOD – 2 (Using comma operator)
Code
x = int(input("Enter the value of x: "))
y = int(input("Enter the value of y: "))
# Swapping of two variables
# without using third variable
x, y = y, x
print("nValue of x:", x)
print("Value of y:", y)
Output –
Enter the value of x: 5
Enter the value of y: 6
Value of x: 6
Value of y: 5
COUNTING
Problem statement - Given a set of n students’ examination marks (in the range of 0 to 100)
make a count of the number of students that passed the examination. A pass is awarded for all
marks of 50 and above.
Code
# Creating an empty list
marks = []
# number of students
n = int(input("Enter the number of students:
"))
#Getting input of marks and appending into
the list
print("Enter the marks")
for i in range(0, n):
iMarks = int(input())
marks.append(iMarks)
count = 0
for i in range(0, n):
if(marks[i]>=50):
count = count + 1
print(f'{count} students have passed in
total')
Output
Enter the number of students: 7
Enter the marks
55
42
77
63
29
57
89
5 students have passed in total

More Related Content

PPTX
Basic Graphics in Java
PDF
Algorithms Lecture 2: Analysis of Algorithms I
PPT
Exception handling and function in python
PPTX
Iterarators and generators in python
PPTX
PPTX
Constructor and Types of Constructors
PDF
First order logic
PPTX
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
Basic Graphics in Java
Algorithms Lecture 2: Analysis of Algorithms I
Exception handling and function in python
Iterarators and generators in python
Constructor and Types of Constructors
First order logic
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...

What's hot (20)

PPTX
deadlock handling
PPTX
Linear data structure concepts
PPT
Problem solving using Computer
PPTX
Transaction management DBMS
PDF
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
PPTX
Unit 2 linked list
PDF
Data Structures Notes 2021
PPTX
Object Oriented Programming using C++(UNIT 1)
PDF
Programming languages and concepts by vivek parihar
PPTX
Regular expressions in Python
PPTX
File Handling Python
PDF
Datatypes in python
PPT
SEARCHING AND SORTING ALGORITHMS
PPTX
Introduction to programming
PPTX
Ch 3 Assembler in System programming
PPTX
Exception handling c++
PPTX
Deadlock ppt
PPTX
Map filter reduce in Python
PPTX
Error and exception in python
PPTX
Unit I - Evaluation of expression
deadlock handling
Linear data structure concepts
Problem solving using Computer
Transaction management DBMS
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
Unit 2 linked list
Data Structures Notes 2021
Object Oriented Programming using C++(UNIT 1)
Programming languages and concepts by vivek parihar
Regular expressions in Python
File Handling Python
Datatypes in python
SEARCHING AND SORTING ALGORITHMS
Introduction to programming
Ch 3 Assembler in System programming
Exception handling c++
Deadlock ppt
Map filter reduce in Python
Error and exception in python
Unit I - Evaluation of expression
Ad

Similar to Problem solving using computers - Unit 1 - Study material (20)

PDF
Problem solving using computers - Chapter 1
PPTX
UNIT 1.pptx
PPTX
UNIT-1.pptx python for engineering first year students
PPTX
UNIT 1.pptx Programming for Problem Solving
PPTX
Algorithm & data structure lec2
PDF
DSA
PPTX
Data Structures_Introduction to algorithms.pptx
PDF
Introduction to programming : flowchart, algorithm
PDF
Lecture 2 role of algorithms in computing
PPTX
problem_solving - term 1n2 2024_2025 - Slides 1 to 29.pptx
PPSX
Problem solving and design
PPT
UNIT-1-PPT-DESIGN AND ANALYSIS OF ALGORITHMS
PDF
Cse115 lecture03problemsolving
PPT
Programming.pptVBVBBMCGHFGFDFDHGDFKJKJKKJ;J
PPTX
s-INTRODUCTION TO PROBLEM SOLVING PPT.pptx
PDF
GE3151 PSPP _Unit 1 notes and Question bank.pdf
PDF
Unit 1-problem solving with algorithm
PDF
DATA STRUCTURE
PDF
DATA STRUCTURE.pdf
PPTX
INTROTOPROBLEMSOLVING.pptxINTROTOPROBLEMSOLVING.pptx
Problem solving using computers - Chapter 1
UNIT 1.pptx
UNIT-1.pptx python for engineering first year students
UNIT 1.pptx Programming for Problem Solving
Algorithm & data structure lec2
DSA
Data Structures_Introduction to algorithms.pptx
Introduction to programming : flowchart, algorithm
Lecture 2 role of algorithms in computing
problem_solving - term 1n2 2024_2025 - Slides 1 to 29.pptx
Problem solving and design
UNIT-1-PPT-DESIGN AND ANALYSIS OF ALGORITHMS
Cse115 lecture03problemsolving
Programming.pptVBVBBMCGHFGFDFDHGDFKJKJKKJ;J
s-INTRODUCTION TO PROBLEM SOLVING PPT.pptx
GE3151 PSPP _Unit 1 notes and Question bank.pdf
Unit 1-problem solving with algorithm
DATA STRUCTURE
DATA STRUCTURE.pdf
INTROTOPROBLEMSOLVING.pptxINTROTOPROBLEMSOLVING.pptx
Ad

More from To Sum It Up (20)

PPTX
Django Framework Interview Guide - Part 1
PPTX
Artificial intelligence ( AI ) | Guide
PPTX
On Page SEO (Search Engine Optimization)
PDF
Prompt Engineering | Beginner's Guide - For You
PPTX
Natural Language Processing (NLP) | Basics
PPTX
It's Machine Learning Basics -- For You!
PPTX
Polymorphism in Python
PDF
DSA Question Bank
PDF
Web API - Overview
PDF
CSS Overview
PDF
HTML Overview
PDF
EM Algorithm
PDF
User story mapping
PDF
User stories
PDF
Quality Circle | Case Study on Self Esteem | Team Opus Geeks.pdf
PPTX
Multimedia Content and Content Acquisition
PPTX
PHP Arrays_Introduction
PDF
System Calls - Introduction
PDF
Leadership
PDF
Programming The Basic Computer
Django Framework Interview Guide - Part 1
Artificial intelligence ( AI ) | Guide
On Page SEO (Search Engine Optimization)
Prompt Engineering | Beginner's Guide - For You
Natural Language Processing (NLP) | Basics
It's Machine Learning Basics -- For You!
Polymorphism in Python
DSA Question Bank
Web API - Overview
CSS Overview
HTML Overview
EM Algorithm
User story mapping
User stories
Quality Circle | Case Study on Self Esteem | Team Opus Geeks.pdf
Multimedia Content and Content Acquisition
PHP Arrays_Introduction
System Calls - Introduction
Leadership
Programming The Basic Computer

Recently uploaded (20)

PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
MYSQL Presentation for SQL database connectivity
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Cloud computing and distributed systems.
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPT
Teaching material agriculture food technology
PDF
Empathic Computing: Creating Shared Understanding
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Electronic commerce courselecture one. Pdf
PDF
Modernizing your data center with Dell and AMD
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
cuic standard and advanced reporting.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
MYSQL Presentation for SQL database connectivity
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Chapter 3 Spatial Domain Image Processing.pdf
Cloud computing and distributed systems.
Encapsulation_ Review paper, used for researhc scholars
Dropbox Q2 2025 Financial Results & Investor Presentation
Teaching material agriculture food technology
Empathic Computing: Creating Shared Understanding
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Spectral efficient network and resource selection model in 5G networks
Electronic commerce courselecture one. Pdf
Modernizing your data center with Dell and AMD
Unlocking AI with Model Context Protocol (MCP)
cuic standard and advanced reporting.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Agricultural_Statistics_at_a_Glance_2022_0.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx

Problem solving using computers - Unit 1 - Study material

  • 1. Problem solving using computers – Unit 1 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-SOLVING ASPECT – Steps in problem solving – 1. PROBLEM DEFINITION (Problem statement) 2. PROBLEM ANALYSIS (Identify Input, Output, Constraints, Formulas to be used (if any) 3. PROBLEM APPROACH (Algorithm, Pseudo code, Flowchart) 4. CODING 5. COMPILATION & EXECUTION 6. DEBUGGING & TESTING 7. DOCUMENTATION Algorithm – A set of finite rules or instructions to be followed in calculations or other problem- solving operations.
  • 2. Example – Algorithm to add 3 numbers and print their sum (Variables - n1 | n2 | n3 | sum) 1. START 2. Declare 3 integer variables n1, n2 and n3. 3. Take the three numbers, to be added, as inputs in variables n1, n2, and n3 respectively. 4. Declare an integer variable sum to store the resultant sum of the 3 numbers. 5. Add the 3 numbers and store the result in the variable sum. (n1 + n2 + n3) 6. Print the value of the variable sum 7. END Check for language independency – // C PROGRAM #include <stdio.h> int main() { int n1, n2, n3; scanf("%d %d %d",&n1,&n2,&n3); int sum;
  • 3. 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) How to express an Algorithm? • FLOWCHART • PSEUDO-CODE 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.” A flowchart can be helpful for both writing programs and explaining the program to others. When to use a flowchart? 1. To develop understanding of how a process is done 2. To study a process for improvement 3. To communicate to others how a process is done 4. When better communication is needed between people involved with the same process 5. To document a process 6. When planning a project
  • 4. 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.
  • 5. RULES OF PSEUDO-CODE • 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
  • 6. • 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. Example: Write a 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 Top-down design approach – 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.
  • 7. Top-Down Model is followed by structural programming languages like C, Fortran etc. EXAMPLE – // User-defined function void add(int a, int b) { printf("%d + %d = %d", a+b); } // Driver code int main() { int a,b; scanf("%d%d", &a, &b); add(a,b); //Function call return 0; } The function call is the main task, which calls the subtask that has the implementation. It is noted that the main() function is the top-most implementation and execution zone.
  • 8. Program testing – Program testing is the process of executing a program with the intent of finding errors. A good test is one that has a high probability of finding an error. Program testing cannot show the absence of errors. It can only show if errors are present. Time Complexity – The Time Complexity of an algorithm/code is not equal to the actual time required to execute a particular code, but the number of times a statement executes. And, there exists a relation between the input data size (n) and the number of operations performed (N) with respect to time. This relation is denoted as Order of growth in Time complexity and given notation O[n] where O is the order of growth and n is the length of the input. It is also called as ‘Big O Notation’ There are five types of Time complexity Cases: • Constant Time Complexity - O(1) • Logarithmic Time Complexity - O(log n) • Linear Time Complexity - O(n) • O(n log n) Time Complexity • Quadratic Time Complexity - O(n2)
  • 9. Loops and Time complexity – 1. O(N) for(i=0; i < N; i++){ some O(1) expressions } The Time Complexity of a loop is considered as O(n) if the loop variables are incremented/decremented by a constant amount. 2. O(N^2) for(i=0; i < N; i++) { for(j=0; j < N;j++){
  • 10. some O(1) expressions } } The time complexity is defined as an algorithm whose performance is directly proportional to the squared size of the input data, as in nested loops it is equal to the number of times the innermost statement is executed. 3. O(log N) for (int i = 1; i <= N; i *= c) { // some O(1) expressions } for (int i = N; i > 0; i /= c) { // some O(1) expressions } The time Complexity of a loop is considered as O(log n) if the loop variables are divided/multiplied by a constant amount. And also for recursive calls in the recursive function, the time Complexity is considered as O(log n). Space complexity – The space Complexity of an algorithm is the total space taken by the algorithm with respect to the input size. Space complexity includes both Auxiliary space and space used by input. Space Complexity = Auxiliary Space + Space used for input values
  • 11. EXCHANGING/SWAPPING OF VARIABLES Problem statement – Given two variables x and y, exchange the values assigned to them. METHOD – 1 (Using third variable) Code x = int(input("Enter the value of x: ")) y = int(input("Enter the value of y: ")) # Swap using third variable temp = x x = y y = temp print("nAfter exchanging - ") print("Value of x:", x) print("Value of y:", y) Output – Enter the value of x: 5 Enter the value of y: 6 After exchanging - Value of x: 6 Value of y: 5 METHOD – 2 (Using comma operator) Code x = int(input("Enter the value of x: ")) y = int(input("Enter the value of y: ")) # Swapping of two variables # without using third variable x, y = y, x print("nValue of x:", x) print("Value of y:", y) Output – Enter the value of x: 5 Enter the value of y: 6 Value of x: 6 Value of y: 5
  • 12. COUNTING Problem statement - Given a set of n students’ examination marks (in the range of 0 to 100) make a count of the number of students that passed the examination. A pass is awarded for all marks of 50 and above. Code # Creating an empty list marks = [] # number of students n = int(input("Enter the number of students: ")) #Getting input of marks and appending into the list print("Enter the marks") for i in range(0, n): iMarks = int(input()) marks.append(iMarks) count = 0 for i in range(0, n): if(marks[i]>=50): count = count + 1 print(f'{count} students have passed in total') Output Enter the number of students: 7 Enter the marks 55 42 77 63 29 57 89 5 students have passed in total