Lecture 2 Algorithm Analysis
Memory
- A finite sequence of cells, each cell has the same
number of bits. - Every cell has an address: the first cell of memory has address 0, the second cell 1, and so on.
- Store information for immediate use in a computer
- Computer hardware devices
Center Process Unit (CPU)
- Contains a fixed number of registers
- Basic (atomic) operations
- Initialization
- Set a register to a fixed values (e.g., 100, 1000, etc.)
- Arithmetic (ALU)
- Take integers a, b stored in two registers, calculate one of {+, -, *, /} and store the result in a register
- Comparison / Branching
- Take integers a, b stored in two registers, compare them, and learn which of {a<b, a=b, a>b} is true
- Memory Access
- Take a memory address A currently stored in a register Do the READ (i.e., load data from memory) or WRITE (i.e., flush data to memory) operator
- Initialization
Algorithm Analysis
- Cost analysis (running time): length of the sequences, i.e., the number of basic operations
- Correctness analysis: Proof your algorithm is correct, Guarantee your implementation is correct
Worst Case Analysis
In computer science, it is an art to design algorithms with performance guarantees.
Big-O notation
Let and be two functions of .
We say that grows asymptotically no faster than if there is a constant such that:
holds for all .
We denote this by
Example
Problem:
Proof:
let , so that
Support that are constant ,so that:
However, as grows, also grows without bound, which contradicts the assumption that it is bounded by a constant.
Worst-Case of Algorithms
| E.g., Compare two numbers | |
| E.g., Binary search (on a sorted array) | |
| E.g., Linear search (on an unsorted array) | |
| E.g., Merge sort | |
| E.g., Selection sort | |
| E.g., Matrix multiplication | |
| E.g., Brute-force search on Boolean satisfiability | |
| E.g., Brute-force search on traveling salesman |
Big-Ω notation
Let and be two functions of .
We say that grows asymptotically no slower
than if there is a constant such that:
holds for all .
We denote this by .
Examples:
Big-Θ notation
Let and be two functions of .
If and , then we define
to indicate grows asymptotically as fast as .