DSA1 | Week 7

Keeping Time

Summary from last week

Defined stable matchings as the absence of blocking pairs.

Deferred Acceptance Algorithm

Key Idea.

Cost in terms of time & space

A specific implementation of an array algorithm, implemented in a specific programming language, and running on a specific machine, might have a running time of approximately f(n) = 0.0023 \cdot n^2

f(n)=0.0023n seconds

on arrays of length nn. 

 

We will call that the cost, in seconds, of running this algorithm.

The constant 0.00230.0023 is an important part of that cost measurement in terms of the stopwatch time, but it doesn’t tell you anything meaningful about the algorithm.

What we need is a better way to describe cost that doesn't rely on the details of the implementation and computer processor speed, but rather is inherent to the algorithm itself.

A more predictable measurement than stopwatch time is the number of “basic operations” that an algorithm has to perform.

But what is a “basic operation”?

 

This depends on the problem that you are trying to solve.

  • manipulate numbers: you can count the number of arithmetic operations.

  • manipulate arrays: you may count the number of times array locations are written to or read from.

  • manipulate arrays by comparing and swapping elements: you can count the number of times array elements were compared or swapped.

Best Case, Worst Case, Average Case

Best case: what if you got lucky?

Worst case: what if you got very unlucky?

Average case: what is the big picture?

Binary Search  ⸱  Ternary Search.

DSA1 | Week 7

By Neeldhara Misra