---
+# Sorting with cards
+
+Classroom activity?
+
+Don't forget bogosort!
+
+---
+
# Dealing with complex problems: some terms to know
(M269 Unit 5)
Build a soluion bottom-up from subparts
-## Heuristics
+---
+
+# Heuristics
* Posh word for "guess"
* Greedy algorithms
* Backtracking
+
---
-# Sorting with cards
+# Making change
-Classroom activity?
+Given
+
+* some money and a set of coin denominations,
+
+find
+
+* the smallest number of coins to make that total.
+
+## Approach 1: greedy
+
+```
+Repeat:
+ Pick the biggest coin you can
+```
+
+Only works in some cases
+
+(What the best way to make 7p if you have 1p, 3p, 4p, 5p coins?)
+
+---
+
+# Making change 2: exhaustive search
+
+.float-right[![Ticket to Ride](make-change.dot.png)]
+
+Make a tree of change-making.
+
+Pick the optimal.
+
+---
+
+# Making change 3: dynamic programming
+
+Bottom-up approach
+
+Initial:
+
+0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | ...
+-|-|-|-|-|-|-|-|-|-|-|-
+(0, 0, 0) | (0, 0, 0) | (0, 0, 0) | (0, 0, 0) | (0, 0, 0) | (0, 0, 0) | (0, 0, 0) | (0, 0, 0) | (0, 0, 0) | (0, 0, 0) | (0, 0, 0) | ...
+
+--
+----
+0* | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | ...
+-|-|-|-|-|-|-|-|-|-|-|-
+(0, 0, 0) | (1, 0, 0) | (0, 1, 0) | (0, 0, 0) | (0, 0, 0) | (0, 0, 1) | (0, 0, 0) | (0, 0, 0) | (0, 0, 0) | (0, 0, 0) | (0, 0, 0) | ...
+
+--
+----
+0 | 1* | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | ...
+-|-|-|-|-|-|-|-|-|-|-|-
+(0, 0, 0) | (1, 0, 0) | (0, 1, 0) | (0, 0, 0) | (0, 0, 0) | (0, 0, 1) | (0, 0, 0) | (0, 0, 0) | (0, 0, 0) | (0, 0, 0) | (0, 0, 0) | ...
+
+--
+----
+0 | 1 | 2* | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | ...
+-|-|-|-|-|-|-|-|-|-|-|-
+(0, 0, 0) | (1, 0, 0) | (0, 1, 0) | (1, 1, 0) | (0, 2, 0) | (0, 0, 1) | (0, 0, 0) | (0, 1, 1) | (0, 0, 0) | (0, 0, 0) | (0, 0, 0) | ...
+
+--
+----
+0 | 1 | 2 | 3* | 4 | 5 | 6 | 7 | 8 | 9 | 10 | ...
+-|-|-|-|-|-|-|-|-|-|-|-
+(0, 0, 0) | (1, 0, 0) | (0, 1, 0) | (1, 1, 0) | (0, 2, 0) | (0, 0, 1) | (0, 0, 0) | (0, 1, 1) | (1, 1, 1) | (0, 0, 0) | (0, 0, 0) | ...
---
## Travelling Salesman Problem
-Online: http://www.math.uwaterloo.ca/tsp/games/tspOnePlayer.html
+.float-right[![Ticket to Ride](ticket-to-ride-small.jpg)]
+
+Online:
+
+http://www.math.uwaterloo.ca/tsp/games/tspOnePlayer.html
* But many implementations are Java applets, now a problem with security settings
Try Android/iOS apps?
-## Change-finding problem
-
-Same as the Knapsack problem: M269 Unit 5 Section 3.2, especially Activity 5.9
+## Ticket to Ride boardgame
-Dynamic programming to find solution
+Graph algorithms
-## Ticket to Ride boardgame
+* Find shortest path
---
--- /dev/null
+digraph G {
+ ten [label="10\n0, 0, 0"];
+ nine [label="9\n1, 0, 0"];
+ eight [label="8\n 0, 1, 0"];
+ eighta [label="8\n2, 0, 0"];
+ five [label="5\n0, 0, 1"];
+ seven [label="7\n1, 1, 0"];
+ four [label="4\n1, 0, 5"];
+ six [label="6\n0, 2, 0"];
+ three [label="3\n0, 1, 1"];
+ five [label="5\n0, 0, 1"];
+ zero [label="0\n0, 0, 2"];
+ sixa [label="6\n2, 1, 0"];
+ fivea [label="5\n1, 2, 0"];
+ two [label="2\n1, 1, 1"];
+
+ ten -> nine;
+ ten -> eight;
+ ten -> five;
+
+ nine -> eighta;
+ nine -> seven;
+ nine -> four;
+
+ seven -> sixa;
+ seven -> fivea;
+ seven -> two;
+
+ eight -> seven;
+ eight -> six;
+ eight -> three;
+
+ five -> four;
+ five -> three;
+ five -> zero;
+}