3.5 Algorithm Efficiency and Scalability
Algorithms and Problem Solving
3.5.1 Efficiency
Algorithm efficiency refers to how well an algorithm uses resources like time and space (memory) to solve a problem. The efficiency of an algorithm is typically evaluated based on its time complexity (how the run time increases as the input size increases) and space complexity (how the memory usage grows as the input size increases).
Example: Consider two sorting algorithms: Bubble Sort and Merge Sort. Bubble Sort has a time complexity of O(n²), meaning that if the input size doubles, the time taken increases by four times. Merge Sort, however, has a time complexity of O(n log n), which grows much more slowly as the input size increases, making it more efficient for large datasets.