1/54
Looks like no tags are added yet.
Three Criteria For Alogrithms (Lecture)
Correctness, Efficiency, Readability
Worst Case For Based Sorting (Lecture)
O (n log n)
Alogrithms (1)
A procedure that takes any of the possible input instances and transforms them into the desired output.
Problem
A specification of inputs and expected outputs they paired with, function contract, signature.
Problem: Robot Tour Optimization (1.1)
Input: A set S of n points in the plane
Output: What is the shortest cycle tour that visits each point in the set S?
OptimalTSP(P)
d=infinity
For each of the n! permutations P(i) if the point set O
if (cost(P(i)) <= d) then d = cost(P(i) and P(min) = P(i)
Return P min
Guarnteed shortest possible tour, but is extremely slow.
Problem: Movie Scheduling Problem (1.2)
Input: A set I intervals on the line.
Output: What is the largest subset of mutually non-overlapping intervals that can be selected from I?
Optimal Scheduling(I)
While (I ~= empty set)
Accept the job from h from I with the earliest completion date
Delete j, and any interval which intersects j, from I
Reasoning About Corretness (1.3)
We need tools to distingush corect algorithms from incorrect ones, the primary one of which is called a proof.
Proper Mathmatical Proof (1.3)
It consists of several parts: first, a clear, precise statement of what you're trying to prove. Second is a set of assumptions of things that are taken to be true and can be part of the proof, and third is the chain of reasoning that takes you from these assumptions to the statement you are trying to prove.
Problem Specification (1.3.1)
Has Two Parts: (1) the set of allowed input instances, and (2) the required properties of the algorithm’s output.
Verifability (1.3.3)
To demonstrate that a particular instance is a counterexample to a particular algorithm, you must be able to (1) calculate what answer your algorithm will give in this instance and (2) display a better answer so as to prove that the algorithm didn’t find it.
Simplicity (1.3.3)
A good counterexample has all unnecessary details stripped away. They make it clear exactly why the proposed algorithm fails. Simplicity is important because you must be able to hold the given instance in your head in order to reason about it. Once a counterexample has been found, it is worth simplifying it down to its essence.
Think exhaustively (1.3.3)
There are usually only a small number of possible instances for the first non-trivial value of n. For example there are only three distince ways two intervals on the line can occur: as disjoint intevals as overalloing intervals, and as properly nesting intervals, one within the other. All cases of three intervals (including counter examples, to be both of the movie heuristics) can be systematically constructed by adding a third segment in each possible way to these instances.
Hunt for weakness
If a proposed algorithm is of form “alwats take the biggest“ (better known as the greedy algorithm), htink about why that might prove to be the wrong thing to do in particular,…
Go for a tie
A devious way to break a greedy herusutc us to provide instances where everything is the same size. Suddenly the heurisitc has nothing to base its decision on, and perhaps has the fredom to return something suboptimal as the answer
Seek extremes
Many counter examples are mixtures of huge and tiny, left and right, few and many, near and far. It is usually easier to verify or reason about extreme examples, than more muddled ones. Consider two tightly bunched clouds of points seperated by a much larger distance d. The optimal TSP tour will be essentially 2d regardless of the number of points, because what happens within each cloud doesent really matter.
Recursion And Induction
A proof or demonstarte of corrects is often mathmatical induction.
Modeling (1.5)
Tge act if formulating your application in terms of precisely described, well understood problems. Proper modeling is the key to applying algorithmic design techniques to real world problems.
Proof By Contradiction (1.6)
Assume that the hypothesis (the statement you want to prove is false)
Develop Some logical consequence of this assumption
Show that one consequense is demonstrably false, thereby showing that the assumption is incorrect and the hypothesis is true.
War Story: Pyschic Handling 1.8 Theme
Make sure you model your problem correctly before trying to solve it.
Estimation 1.9
Principle Guessing, the ability to make back of the envelope estimates of diverse quantities such as the running time of a program is a valuable skill in algoruthmn design.
For a cmapus of n points hw many possible tours are there? It must hit every single point once (and only once), and also return to the starting point.
n!
RAM
Random Access Machine
Memory Acess
Each meemory acess takes exactly one time step.
RAM Model
Excellent model for understanding how an alogorithm will perform on a real computer.
Worst case complexity
Maximum number of steps taken in any instance of size in
Best Case complexity
Minimum number of steps taken un any instance of size n.
Average Case Complexity
Average number of steps over all instances of size n
2.9 War Story Theme
To show enmourmous potential for algorithmic speedups, as opposed to the fairly limited speedup obtainable via more expensive hardware.
3.1 Contiguous Data Strucutures
Allocated structures that are composed of single slabs of memory and includes arrays, matrices, heaps, and hash tables.
3.1 Linked Data Strucutures
Composed of distinct chunks of memeory bound together my pointers, and includes lists, trees, and graph adjacency lists.
3.1.1 Arrays
Fundamental contiguosly allocated data structure, fixed size data records that each element can be efficienty located by its index or equivalently address.
.1.1 Advantages of contiguously allocated arrays include:
Constant Time Acess Given The Index
Space Efficiency
Memory Locality
3.1.2 Pointers
The connc\ections that hold the pieces of linked structures together.
3.1.3 Advantages of Linked structures over static arrays include:
Overflow on linked structures never occurs unless memeory is actually full
Insertion and deletion are simpler than for static arrays
With large recrods, moving pointers is easier and faster than moving the items themselves
3.1.3 Advantages of arrays include
Space Effciency
Efficient random acess to items in arrays
Better memeory locality and cache performance than random pointer jumping
3.5 Priority Queues
An abstract data type that provides more flexibility than simple sorting, because it alows new elements to enter a system at arbitrary intervals.
3.6 War Story Theme
Using the greedy heuristic can significantly improve perfromance over the niave approach.
3.9 War Story Theme
Persistence Pays Off
List Scenario (Lecture)
I need elements at arbitrary positions
Queue Scenario (Lecture)
I need to get things order that they were placed
Map Scenario (Lecture)
I need to look up values by {name, phone number, space values}
List (Lecture)
A linear ordering of values that allows duplicates and random (arbitrary) access. (Linear ADT)
Queue (Lecture)
A sequence of items whic can be acessed first-in, first-cut(fifo). (Linear ADT)
Stack (Lecture)
A sequence of items which can be acessed last-in, first-out. (Linear ADT)
Dequeue (Lecture)
A sequence of items which can acessed from wither end. (Linear ADT)
Priority Queue (Lecture)
A set of items that can be acessed by their priority (Linear ADT)
Bag
Unordered collection of values (Unordered ADT)
Set
An unordered collection of values that does not allow duplicates (Unordered ADT)
Map
A colletion of unique keys associated with values (Unordered ADT)
Abstract Data Type (ADT)
Specification of an interface for a type, implies but does not gurantee data structure
Data structure
A concrete implemnetation of an ADT
Variable
An ADT, that stores name and value (name,value) and reads name that points to a value, (name)→value
Denominator grows quicker To Infinty
Big O notation
Numerator Grows Quicker To Infinity
Omega Notation
Big O And Omega Holds,
Ex: 2n/1n = 2 so Theta Notation