Factors Influencing The Performance of Algorithms - Computational Complexity - Classification of Algorithms
Factors Influencing The Performance of Algorithms - Computational Complexity - Classification of Algorithms
Performance of Algorithms
- Computational Complexity
- Classification of Algorithms
What is an Algorithm?
An algorithm is a step-by-step guide or a set of
instructions to solve a problem or do a task.
Examples:
A recipe for cooking a dish (a set of steps to
prepare food).
Instructions to find a phone number in a contact
list.
Factors Influencing the Performance of
Algorithms
These are the things that affect how fast or slow an
algorithm works.
Key Factors:
Size of the input (how much data you have).
Time it takes to run (time complexity).
Memory it uses (space complexity).
The environment it runs in (hardware and software).
Input Size
The number of elements (like numbers or characters) the
algorithm has to work with.
Impact: The more data you have, the longer it may take for
the algorithm to finish.
Example: A sorting algorithm takes longer to sort 1,000
numbers than 10 numbers because there is more data to
process.
Time Complexity
A way to measure how the time needed for an algorithm to
run, changes with the size of the input.
Common Notations:
O(1): Takes the same amount of time, no matter how big
the input is.
O(n): Time grows directly with the size of the input.
O(n^2): Time grows with the square of the input size (if
the input size doubles, the time grows four times).
Example: Finding a name in a sorted phone book using
binary search takes much less time (O(log n)) than checking
every name one by one (O(n)).
Space Complexity
A way to measure how much extra memory an algorithm
needs to run.
Types of Space:
Input Space: Memory required to store the input data.
Auxiliary Space: Extra memory the algorithm needs
apart from the input data.
Example: A sorting algorithm that uses extra space to store
a new list while sorting has higher space complexity than
one that sorts in place without extra memory.
Hardware and Software Environment
CPU Speed: Faster processors can execute more instructions in a
second.
Memory Size: More memory can allow for larger data sets and better
performance.
Compiler Optimizations: Some compilers translate code more
efficiently.
Operating System: The OS can impact performance based on how it
manages resources.