Analysis Wrap-up
What is analysis? Look at an algorithm and determine: How much time it takes How much space it takes How much programming manpower it takes Choose wisely between multiple correct solutions
Problem-Solving Brute Force Iterate Divide-and-Conquer Greedy Dynamic Programming
Model the world Arrays & Linked Lists Stacks & Queues Priority Queues & Heaps Graphs & Trees Binary Search Trees Hash tables
Famous (Efficient) Algorithms Binary Search Find the median Sort Graph Search Topological Sort Shortest Path Minimum Spanning Trees Knapsack Problem Huffman’s Encoding
The Point Know your problem-solving tools Be able to choose the right tool for the job Know the limits of your tools…
Back to Theory Sets: NP, P, NP-Complete Prove NP-Complete through reduction proofs. But: some things are uncomputable, and this is different from NP-Complete.
What Next? What do you do when you need to solve an NP-Complete problem? Redefine the problem Approximate a solution Use AI techniques!
Intelligent Search If I have to use brute force, I want to do it smartly. Heuristics! Add a “good enough” threshold so you can stop searching when you find an approximate solution. One such technique is Genetic Algorithms…
Genetic Algorithms Inspired by biology/evolution Start with a random sample of possible solutions Fitness Function: test how good each solution is Make new solutions: Make a small mutation to an existing solution Cross-breed 2 existing solutions Keep best solutions and discard the rest. Iterate until you run out of time
Example: TSP Trying to visit 5 cities: A, B, C, D, E Randomly make some possible paths: BDECA, ABCED, … Try them. Fitness Function? Mutate: BD ECA -> DB ECA Crossover: BD ECA + A B CE D = BDACE (First 2 of the first parent and rest of ordering from 2 nd parent.)
TSP Example: 30 Cities
Solution i (Distance = 941)
Solution j (Distance = 800)
Solution k (Distance = 652)
Best Solution (Distance = 420)
Overview of Performance