1. Algorithms

A well-defined procedure:

The procedure must work for all instances of the problem.

Defining Algorithms

Properties

Determining Correctness

Testing can not prove an algorithm is correct (unless you can test all cases): you can only prove it is incorrect. Only formal proofs can prove it. Not covered in the course.

Start with a reasonably precise statement of the problem and algorithm.

Then:

Example: Robot Arm (Skiena 1.1)

Robot needs to place solder into nn points on a PCB. What is the shortest cycle tour that visits each point in the set SS? This is the TSP, so an optimal solution cannot be found. Thus, heuristics need to be used.

Heuristics: greedy algorithm?

Example: Selecting Jobs (Skiena, 1.2)

Multiple movies that need to be filmed, need to maximize number of movies. Set II of nn intervals on the line.

Heuristics: start with the shortest movie? Start with the first available movie?

Look for counter examples that show that the heuristic is incorrect:

Proof by induction

def sum(n):
    s = 0
    for i in range(1, n + 1):
        s += i
    return s

Assume that the loop works up to kk. Thus, the loop must work up to when calculating the sum for k+1k+1.

Insertion sort

After nn iterations of the outer for loop, the sub array, [0,n)[0, n) is sorted. Now, you only need to prove that it is able to sort the nnth element correctly.