2025-09-03
# Prints the running times for problem sizes that double, using a single loop.
import time
problemSize = 10000000
print("%12s%16s" % ("Problem Size", "Seconds"))
for count in range(5):
start = time.time()
# The start of the algorithm
work = 1
for x in range(problemSize):
work += 1
work -= 1
# The end of the algorithm
elapsed = time.time() - start
print("%12d%16.3f" % (problemSize, elapsed))
problemSize *= 2| Problem Size | Seconds |
|---|---|
| 10,000,000 | 0.680 |
| 20,000,000 | 1.361 |
| 40,000,000 | 2.709 |
| 80,000,000 | 5.330 |
| 160,000,000 | 10.665 |
Lists11 to 13 now look like below:problemSize = 1000 before running the new programwith only two problems:
A graph of the amounts of work done in the tester programs 
n^k, k = constant or > 12ⁿA graph of some sample orders of complexity

| n | Logarithmic (log₂n) | Linear (n) | Quadratic (n²) | Exponential (2ⁿ) |
|---|---|---|---|---|
| 100 | 7 | 100 | 10,000 | Off the chart |
| 1,000 | 10 | 1,000 | 1,000,000 | Off the chart |
| 1,000,000 | 20 | 1,000,000 | 1,000,000,000,000 | Really off the chart |
big-O notation:
O” stands for “on the order of,” a reference to the order of complexity of the work of the algorithmSearch AlgorithmsindexOfMin Algorithm:
Bubble sortBubble sort algorithm:Bubble sort algorithm analysisBubble Sort AlgorithmSelection Sort Algorithmlist of length n,

Selection sort algorithm:Insertion Sort AlgorithmInsertion sort algorithm:Insertion Sort AlgorithmInsertion sortInsertion sortO(n²)