Page 66 - 2502_Pakistan-kifayat_C-8
P. 66
Cannot solve all problems: Some problems, especially those involving subjective judgment or
emotions, cannot be solved purely by algorithms.
ALGORITHM PERFORMANCE AND EFFICIENCY
Performance refers to how quickly and effectively an algorithm completes its task. The two most
important aspects are:
Time: How long the algorithm takes to run.
Memory: How much additional memory the algorithm requires during execution.
Efficiency is about optimising resource usage — getting the result using the least possible time and
memory.
Time efficiency (Time complexity): Indicates how the runtime grows as input size increases.
Space efficiency (Space complexity): Measures how much extra memory is needed. Some
algorithms use little memory (in-place algorithms), while others require extra storage (like merge
sort).
Example: If you want to sort your toys by colour:
One way is to check every toy again and again — slow!
Another way is to group toys by colour first, then sort each group — faster!
How to Evaluate Algorithm Efficiency?
Algorithm efficiency means how well an algorithm works. To check this, we look at two main things:
1. Speed (Time)
How fast does the algorithm finish the job?
Does it take a few seconds or many minutes?
Fewer steps mean faster work!
2. Memory (Space)
How much extra space or memory does the algorithm need?
Does it need a big box to hold things, or just a small space?
Example: Imagine you have a list of 10 names, and you want to find one name.
Algorithm 1: Checks each name one by one — this might take longer.
Algorithm 2: Splits the list in half each time and quickly finds the name — this is faster!
So, Algorithm 2 is more efficient because it finishes faster.
Comparing Algorithms for the Same Task
Sometimes, there are many ways (algorithms) to solve the same problem. We compare them to choose
the best one.
64 Premium Edition-VIII

