Algorithms
Algorithms
Finite sequence of steps to solve a problem
- Doesn't have to be programming
Examples
- Write an algorithm to decide if a number N is prime
- Go up to the square of N
- Give an algorithm to get out of the room
- Walk to the door
- Open the door
- Walk out
The level of detail and description depend on who or what is executung the algorithm
- Write an algorithm to make a whisky sour
- There are more variables
Writing steps to implement simple task is not trivial
Algorithms vs programs
Algorithms:
A set of well defined instructions
Programming languages
Formal languages for instructing a computer
Program
A set of instructions written in a programming language
Basic elements of algorithms
- Loops
- Conditionals
- Functions
- Variables