# Algorithms

Understanding Algorithms

• An algorithm is a precise list of instructions to complete a task. It’s like a recipe for a computer.

• Algorithms can be used for a wide range of tasks and are crucial in problem solving.

• They should be specific (clear and detailed), unambiguous (no room for varied interpretation), and effective (they work!).

• Algorithms can be written in natural language, pseudocode, or flow charts.

Creating Algorithms

• All algorithms involve a process of problem decomposition – breaking a problem into smaller, manageable parts.

• Algorithms need inputs (data to process), processes (what to do with the data), and outputs (the result).

• Creating algorithms involve logical thinking – you need to thoroughly understand the problem to develop a solution

Evaluating and Improving Algorithms

• When evaluating an algorithm consider its correctness (does it produce the desired output?), and efficiency (how quickly and resourcefully does it solve the problem?).

• An algorithm’s complexity (measured in terms of time or space) can impact its real-world usability.

• Algorithm’s efficiency can be addressed by refining the algorithm – consider the steps, can anything be combined or removed?

• Algorithms can be tested using trace tables to visually track what’s happening step by-step.

Types of Algorithms

• There are numerous types, including: searching algorithms (finding a specific item in a list), sorting algorithms (organising items in a specific order), and computational algorithms (perform calculations).

• Key searching algorithms include: linear search (checking every item in order), and binary search (repeatedly dividing the list in half).

• Key sorting algorithms include: bubble sort (comparing adjacent items and swapping them if in wrong order), and merge sort (dividing list repeatedly into two halves until each sublist has one element, then merging them back in sorted order).

• Computational algorithms could involve various math functions, such as calculating Fibonacci sequence or factorial of a number.