Algorithm
What is Algorithmic Thinking?
Algorithmic Thinking is the process of solving problems using step-by-step instructions.
It involves logical decisions like:
Adding numbers
Checking conditions
Repeating steps (loops)
What is an Algorithm?
Definition: A sequence of clearly defined and ordered steps to solve a problem.
Two main principles:
Definiteness – Steps must be clear and unambiguous.
Sequential Order – Steps must follow a specific order with a clear start and end.
State of an Algorithm
The state refers to what’s happening at a certain step in the process.
Example:
a = 4 a = 40 a = 400 b = a c = a / 40The state changes at each step, affecting variables (
a,b,c).
Algorithms vs. Programs
Algorithm: General step-by-step procedure for solving a problem.
Program: A set of instructions written in a programming language for a computer to execute.
How to Write an Algorithm?
Can be written in:
Natural language (simple sentences)
Programming languages (Python, Java, etc.)
Flowcharts (graphical representation)
Importance of Sequence in Algorithms
Order of execution matters!
Example:
6 / 2 * (2 + 1)Left Calculator:
6 / [2 * 3] = 6 / 6 = 1Right Calculator:
[6 / 2] * 3 = 3 * 3 = 9Different results due to order of operations!
How to Structure an Algorithm?
Input → What information do we start with?
Process → What steps transform the input into the solution?
Output → What is the final result?
Flowcharts & Algorithm Representation
Flowchart Symbols:
Oval: Start/End
Parallelogram: Input/Output
Rectangle: Process
Diamond: Decision
Example: Flowchart for calculating a final grade.
Programming & Algorithmic Thinking
Logic Formulation:
You can find multiple ways to solve a problem.
Creativity matters!
Syntax:
You must follow rules of a programming language to express logic correctly.
Example in Python:
name = input("What’s your name? ") age = input("What’s your age? ") print("Hello", name, "! Nice to meet you.")
Python Programming & Algorithmic Thinking
Python is a high-level programming language with:
Readable syntax
Simple structure
Dynamic execution
Example:
students = int(input("Enter number of students: ")) sections = int(input("Enter number of sections: ")) students_per_section = students / sections print("Each section has", students_per_section, "students.")
Why is Programming Useful?
Computers follow instructions exactly.
Humans can adapt to errors, but computers cannot.
Understanding programming helps develop problem-solving skills.
Key Takeaways
Algorithmic thinking is essential for problem-solving.
An algorithm is a structured, step-by-step procedure.
Programs execute algorithms using programming languages.
Python makes it easier to write algorithms.