UCEST105: Algorithmic Thinking with Python - Module 1 Quick
Notes
UCEST105: Algorithmic Thinking with Python - Module 1 Quick Revision Notes
PART 1 – Problem Solving Strategies
Problem-Solving Strategy:
A plan or method used to find a solution or overcome a challenge.
Steps: Identify → Define → List Solutions → Evaluate → Implement
Types of Problems:
Well-Defined vs Ill-Defined
- Well-defined: Clear goals & single solution
- Ill-defined: Vague goals, many possible solutions
Common Strategies:
- Trial & Error: Try → Check → Repeat
- Algorithm: Step-by-step method guaranteeing correct result
- Heuristics: Quick rule of thumb (Guess & Check / Working Backward)
- Means-Ends Analysis (MEA): Break big goal into smaller sub-goals (Tower of Hanoi)
- Backtracking: Explore all paths, backtrack on dead ends (Maze / Sudoku)
PART 2 – Problem Solving Process
Basic Model of Computer:
I/O Unit, CPU (ALU + CU + Registers), Memory (Primary + Secondary)
Instruction Cycle: Fetch → Decode → Execute → Store → Repeat
Steps in Problem Solving:
1. Understanding the problem
2. Formulating a model
3. Developing an algorithm
4. Writing the program
5. Testing the program
6. Evaluating the solution
Example Programs:
Sum of two numbers:
n1 = 21; n2 = 7; print('Sum =', n1 + n2)
Average of n numbers:
n = int(input("Enter n: "))
total = 0
for i in range(1, n+1): total += i
print("Average =", total/n)
Discriminant of Quadratic Eqn:
d = b**2 - 4*a*c
PART 3 – Essentials of Python Programming
Features: Easy, interpreted, OOP, portable, huge libraries
Translators:
Assembler, Compiler, Interpreter (line-by-line)
Variables & Literals:
Variable = named memory location. Auto type declaration.
Literals: numeric, string, boolean, collections
Data Types:
int, float, complex, string, list, tuple, dict, set, boolean
Math Module (import math):
sqrt, ceil, floor, fabs, pi, factorial, gcd, exp, pow, log, sin, cos, tan
Input / Output:
name = input("Enter name: "); print("Hello", name)
a,b = input("Enter two numbers: ").split()
Operators:
Arithmetic, Comparison, Assignment, Logical, Bitwise, Membership, Identity
Operator Precedence (High → Low):
** → * / // % → + - → < > == != → and → or