ALGORITHMIC THINKING WITH PYTHON
UCEST105
2024 Scheme
S1 Cyber Phisical Systems
GEC Thrissur
1
PROBLEM-SOLVING PROCESS
● Problem solving and use of Computer as a Computation model
● Problem-solving in computer science refers to the systematic
process of breaking down complex issues into smaller, manageable
tasks that a computer can execute.
● It involves identifying the problem, understanding its
requirements, and designing a computational approach to solve it.
● The goal of computation model is to develop a precise, efficient,
and scalable solution that can be implemented using algorithms
and programming.
SUDHEER TM 2
PROBLEM-SOLVING PROCESS
● Computers are built to deal with algorithmic solutions, which are
often difficult or very time consuming for humans.
● People are better than computers at developing heuristic solutions.
● Solving a complicated calculus problem or alphabetizing 10,000
names is an easy task for the computer, but the problem of how to
throw a ball or how to speak English is not.
● The difficulty of such things lies in the programming.
SUDHEER TM 3
PROBLEM-SOLVING PROCESS
● The field of computers that deals with heuristic types of problems
is called artificial intelligence.
● Artificial intelligence enables a computer to do things like build its
own knowledge bank and speak in a human language.
● As a result, the computer’s problem-solving abilities are similar to
those of a human being.
● Artificial intelligence is an expanding computer field, especially
with the increased use of Robotics.
SUDHEER TM 4
PROBLEM-SOLVING PROCESS – Steps in problem solving
● Overview of Steps:
1. Understanding the Problem: Analyze the problem’s requirements
and constraints.
2. Formulating a Model: Create an abstract representation of the
problem.
3. Developing an Algorithm: Design a step-by-step procedure to solve
the problem.
4. Writing the Program: Translate the algorithm into code.
SUDHEER TM 5
PROBLEM-SOLVING PROCESS – Steps in problem solving
● Overview of Steps:
5. Testing the Program: Validate the program against different cases.
6. Evaluating the Solution: Assess the effectiveness and efficiency of
the solution.
SUDHEER TM 6
PROBLEM-SOLVING PROCESS – Steps in problem solving
● Understand the problem
● Effective Problem-Solving Begins with Understanding
○ Gain a deep understanding of the problem domain.
○ Identify and clearly define the exact nature of the problem.
○ Understand the environment where the problem exists.
○ Define what needs to be achieved.
○ Identify any limitations or restrictions.
SUDHEER TM 7
PROBLEM-SOLVING PROCESS – Steps in problem solving
● Understand the problem
● For Gathering Information
○ Conduct Interviews: Speak directly with stakeholders to gain
insights.
○ Distribute Questionnaires: Collect structured data from those
involved.
● Break Down the complex Problem into smaller, manageable parts.
○ Simplifying the problem helps to develop a clearer picture.
SUDHEER TM 8
PROBLEM-SOLVING PROCESS – Steps in problem solving
● Formulating a Model for the Solution
● Devising the Solution:
○ Once the problem is fully understood, identify potential ways to solve it.
● Idea Generation Techniques:
○ Brainstorming: Generate a large number of ideas quickly.
○ Brainwriting: Write down ideas individually to promote creativity.
○ Mind Mapping: Visualize and organize ideas to see connections and
relationships.
SUDHEER TM 9
PROBLEM-SOLVING PROCESS – Steps in problem solving
● Formulating a Model for the Solution
● Transforming Ideas into a Model:
○ Convert generated ideas into a conceptual model that outlines the solution.
● Popular Modeling Techniques:
○ Mathematical Modeling: Use mathematical expressions to represent the
problem.
○ Simulation Modeling: Create a simulation to predict and analyze outcomes.
SUDHEER TM 10
PROBLEM-SOLVING PROCESS – Steps in problem solving
● Formulating a Model for the Solution
● Ensuring Model Accuracy:
○ The developed model should accurately represent the
conceptual ideas and be feasible for implementation.
SUDHEER TM 11
PROBLEM-SOLVING PROCESS – Steps in problem solving
● 3. Developing an Algorithm
● In this stage we need to Translate Solutions into Algorithms
● Formalizing Solutions:
○ Convert the identified solutions into formal representations, known
as algorithms.
● Selection Process:
○ Not all solutions will be implemented; the next step is to evaluate
each algorithm.
SUDHEER TM 12
PROBLEM-SOLVING PROCESS – Steps in problem solving
● 3. Developing an Algorithm
● Evaluation Criteria:
○ Memory Usage: Assess how much memory each algorithm requires.
○ Time Complexity: Consider the time it takes for each algorithm to
execute.
○ Code Efficiency: Evaluate the length and complexity of the code.
SUDHEER TM 13
PROBLEM-SOLVING PROCESS – Steps in problem solving
● 3. Developing an Algorithm
● Choosing the Best Algorithm:
○ Based on the assessment, select the most efficient and effective
algorithm for the problem.
SUDHEER TM 14
PROBLEM-SOLVING PROCESS – Steps in problem solving
● 4. Code the algorithm
● In this stage we need to turn the Algorithm into Executable
Code
● Implementation Phase:
○ After selecting the best algorithm, translate it into an executable
program.
○ The program is a set of instructions that represents the algorithm in a
specific programming language.
SUDHEER TM 15
PROBLEM-SOLVING PROCESS – Steps in problem solving
● 4. Code the algorithm
● Coding Approach:
○ Incremental Development: Start by coding the core functionalities first.
○ Gradual Enhancement: Gradually add more features and refinements as
we progress.
○ Ensure the code accurately reflects the logic and steps of the algorithm.
○ Follow best practices for readability, maintainability, and efficiency.
SUDHEER TM 16
PROBLEM-SOLVING PROCESS – Steps in problem solving
● 5. Test the program
● To ensure the Correctness of the code Through Testing.
● Purpose of Testing:
○ After coding, inspect the program to verify its correctness and ensure it
produces the desired output.
● Identifying Errors:
○ Execute the program with different inputs to detect any unexpected
outputs (errors).
○ Errors identified during this process are commonly referred to as bugs.
SUDHEER TM 17
PROBLEM-SOLVING PROCESS – Steps in problem solving
● 5. Test the program
● Testing Strategy:
○ Use a smaller, representative set of inputs to evaluate the program.
Consider using automated testing tools to generate and manage test
cases.
● Debugging Process:
○ Fix the errors identified during testing.
○ Repeat testing and debugging until the program is error-free.
SUDHEER TM 18
PROBLEM-SOLVING PROCESS – Steps in problem solving
● 6. Evaluate the solution
● In this stage we need to Assess the Program’s Effectiveness
● Importance of Evaluation:
○ Ensure the program effectively solves the problem and meets the desired
objectives.
● Defining Evaluation Criteria:
○ Efficiency: How well does the program utilize resources like time and
memory?
SUDHEER TM 19
PROBLEM-SOLVING PROCESS – Steps in problem solving
● 6. Evaluate the solution
○ Feasibility: Is the program practical and achievable within the given
constraints?
○ Scalability: Can the program handle increased loads or expanded
functionality?
● Risk Assessment:
○ Identify and evaluate potential risks associated with deploying the
program.
SUDHEER TM 20
PROBLEM-SOLVING PROCESS – Steps in problem solving
● 6. Evaluate the solution
● Gathering Feedback:
○ Collect both quantitative and qualitative feedback from stakeholders.
○ Use this feedback to make necessary improvements to the program.
● Continuous Improvement:
○ Refine the code based on feedback, ensuring it remains aligned with the
objectives.
○ Subject the improved program to additional rigorous testing.
SUDHEER TM 21
PROBLEM-SOLVING PROCESS – Steps in problem solving
● Case study: The Basic Calculator
● Objective: Creating a basic calculator that can perform addition, subtraction,
multiplication, and division.
● 1. Understand the Problem
● Problem Definition:
● Input: Two numbers and an operator (e.g., +, -, *, /) that specifies the
arithmetic operation.
● Output: The result of the arithmetic operation performed on the two
numbers.
● Example:
● Input: 5, 3, and +
22
● Output: 8 SUDHEER TM
PROBLEM-SOLVING PROCESS – Steps in problem solving
● Case study: The Basic Calculator
● 2. Formulate a Model for the Solution
● Mathematical Model:
● Identify the operations needed based on the input:
● Addition: result = a + b
● Subtraction: result = a - b
● Multiplication: result = a * b
● Division: result = a / b
SUDHEER TM 23
PROBLEM-SOLVING PROCESS – Steps in problem solving
● Case study: The Basic Calculator
● 3. Develop an Algorithm
● Algorithm (Pseudocode):
● Start
● Read the first number (a)
● Read the second number (b)
● Read the operator (op)
SUDHEER TM 24
PROBLEM-SOLVING PROCESS – Steps in problem solving
● Case study: The Basic Calculator
● If op is +, then result = a + b
● Else If op is -, then result = a - b
● Else If op is *, then result = a * b
● Else If op is /, then result = a / b (Check if b != 0)
● Print the result
● Stop
SUDHEER TM 25
PROBLEM-SOLVING PROCESS – Steps in problem solving
● Case study: The Basic Calculator
● 4. Code the Algorithm
# Input the numbers if op == '+':
a = float(input("Enter the first number: ")) result = a + b
b = float(input("Enter the second number: ")) elif op == '-':
# Input the operator result = a - b
op = input("Enter the operator (+, -, *, /): ") elif op == '*':
#Perform the calculation based on the result = a * b
operator elif op == '/':
if b != 0:
result = a / b
else:
result = "Error: Division by zero!"
else:
result = "Error: Invalid operator!"
# Print the result
print("The result is:", result)
SUDHEER TM 26
PROBLEM-SOLVING PROCESS – Steps in problem solving
● Case study: The Basic Calculator
● 5. Test the Program
SUDHEER TM 27
PROBLEM-SOLVING PROCESS – Steps in problem solving
operations = {
● Case study: The Basic Calculator '+': lambda a, b: a + b,
'-': lambda a, b: a - b,
● 6. Evaluate the solution '*': lambda a, b: a * b,
'/': lambda a, b: a / b if b !=
if op == '+': 0 else "Error: Division by
switch (op)
result = a + b zero!"
{
elif op == '-': }
case '+': result = a + b; break;
result = a - b
case '-': result = a - b; break;
elif op == '*': result = [Link](op,
case '*': result = a * b; break;
result = a * b lambda a, b: "Error: Invalid
case '/': if (b != 0) { result = a / b; }
elif op == '/': operator!")(a, b)
else { printf("Error: Division by
if b != 0:
zero!\n"); }
result = a / b
break;
else:
default: printf("Error: Invalid operator!\
result = "Error: Division by
n");}
zero!"
}
else:
result = "Error: Invalid operator!“
SUDHEER TM 28