lec1 intro to algorithm and python
lec1 intro to algorithm and python
• Efficiency in problem-solving
• Basis of computer science
• Applications in various fields (e.g.,
healthcare, transportation, finance)
Characteristics of Algorithms
1. Input: Accepts input values.
2. Output: Produces output values.
3. Definiteness: Steps are clear and precise.
4. Finiteness: Terminates after a finite number of
steps.
5. Effectiveness: Each step is simple and
practical.
Steps to Write an Algorithm
1. Start
2. Input two numbers, A and B
3. Calculate the sum: SUM = A + B
4. Output the result
5. End
What Makes a Good Algorithm?
• Clear: Steps are easy to follow and
understand.
• Efficient: Solves the problem using minimal
time and resources.
• Reliable: Produces correct and consistent
results.
• Flexible: Can adapt to different inputs or
scenarios.
Daily Life Example: Preparing a Meal
1. Choose a recipe.
2. Gather ingredients.
3. Follow cooking steps (e.g., chop, fry, mix).
4. Serve and enjoy.
5. Clean up after the meal.
This is a step-by-step algorithm for meal
preparation.
Daily Life Example: Doing Laundry
1. Gather dirty clothes.
2. Separate clothes by color and fabric type.
3. Load clothes into the washing machine.
4. Add detergent and start the cycle.
5. Dry clothes and fold them.
This algorithm ensures an organized approach to
laundry.
Benefits of Learning Algorithms
• Improves logical thinking.
• Helps in efficient problem solving.
• Forms the foundation for learning
programming.
• Prepares you for real-world tasks and
challenges.
Task: Grocery Shopping Algorithm
► Historical data (e.g., weather, soil conditions, crop type) is fed into
machine learning algorithms.
► Algorithms predict:
► Crop yields for the upcoming season.
► Factors affecting yield (e.g., droughts, pests).
► Applications:
► Helps farmers plan resources efficiently.
► Reduces financial risks.
Example Algorithm: Scheduling
► Problem: Fertilizer application scheduling.
► Solution:
1. Collect weather forecasts.
2. Analyze soil nutrient levels.
3. Determine the best time for fertilizer application.
► Algorithm ensures:
► Optimal growth conditions.
► Reduced waste and environmental impact.
Algorithms in Precision Farming
► Use satellite imagery to monitor crop health.
► Algorithms identify areas with water stress or nutrient
deficiency.
► Recommendations are provided to farmers to address specific
areas.
► Example: Variable rate application of fertilizers.
Introduction to Python
• Python is a beginner-friendly programming
language.
• It uses simple syntax and is easy to learn.
• Python is widely used in data analysis,
automation, and app development.
ASPECTS OF LANGUAGES
primitive constructs
◦ English: words
◦ programming language: numbers, strings, simple
operators
Word Cloud copyright Michael Twardos, All Right Reserved. This content is excluded from our Word Cloud copyright unknown, All Right Reserved.
Creative Commons license. For more information, see https://ocw.mit.edu/help/faq-fair-use/. This content is excluded from our Creative
Commons license. For more information, see
https://ocw.mit.edu/help/faq-fair-use/.
ASPECTS OF LANGUAGES
syntax
◦ English: "cat dog boy" → not syntactically valid
"cat fights dog" → syntactically valid
length = 8
width = 4
area = length * width
print('Area of the rectangle:', area)
Recap
• Algorithms help solve problems systematically.
• Pseudocode is a simple way to write
algorithms.
• Python is a beginner-friendly language to
implement algorithms.
• Practice is key to mastering these concepts.
Tips for Beginners
• Start small: Begin with simple problems.
• Break tasks into smaller steps.
• Practice writing pseudocode before coding.
• Don’t hesitate to ask for help or use online
resources.
Exercise: Writing an Algorithm
Write an algorithm to find the average of three
numbers.
Steps:
1. Start
2. Input three numbers A, B, and C
3. Calculate Average = (A + B + C) / 3
4. Output Average
5. End
Exercise: Writing Python Code
Write a Python program to find the average of three
numbers:
num1 = 12
num2 = 15
num3 = 18
average = (num1 + num2 + num3) / 3
print('Average:', average)
Thank You!