Search⌘ K
AI Features

Comparing Algorithms

Explore how to compare algorithms fairly by focusing on execution time and using analytical methods instead of experimental runs. Understand primitive operations, best-case, average-case, and worst-case analysis, and how to determine time complexity for algorithms using C++.

Introduction

There are typically several different algorithms to solve a given computational problem. It is natural, then, to compare these alternatives. But how do we know if algorithm A is better than algorithm B?

Important Criteria: Time and Space

One important factor that determines the “goodness” of an algorithm is the amount of time it takes to solve a given problem. If algorithm A takes less time to solve the same problem than does algorithm B, then algorithm A is considered better.

Another important factor in comparing two algorithms is the amount of memory required to solve a given problem. The algorithm that requires less memory is considered better. ...