Comparing Algorithms

In this lesson, we are going to learn how two or more algorithms may be compared.

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 “quality” 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 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.

Comparing execution time

For the remainder of this lesson, we will focus on the first factor, i.e., execution time. How do we compare the execution time of two ...

Access this course and 1400+ top-rated courses and projects.