Slide 1

Slide 1 text

Algorithms to live by Elle Meredith @aemeredith

Slide 2

Slide 2 text

Algorithms 1 2 3a 3b = Step by step instructions

Slide 3

Slide 3 text

https://www.instagram.com/p/BaesTAPFaEK2_n5QA06hO7w3Nwd1iaoCS0KIL40/

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

Algorithm Detailed

Slide 7

Slide 7 text

Algorithm Detailed Efficiency Perfection

Slide 8

Slide 8 text

https://imgur.com/Xz3Z2iL

Slide 9

Slide 9 text

In everyday life • Learnt • Figure out ourselves • Require written instructions

Slide 10

Slide 10 text

A precise, systematic method for producing a specified result Definition

Slide 11

Slide 11 text

Why?

Slide 12

Slide 12 text

Suppose we want to search for a word in the dictionary Binary Search

Slide 13

Slide 13 text

1 2 3 4 100 …

Slide 14

Slide 14 text

1 2 3 4 100 … X Too low

Slide 15

Slide 15 text

1 2 3 4 100 … XX Too low

Slide 16

Slide 16 text

1 2 3 4 100 … XXX Too low

Slide 17

Slide 17 text

1 2 3 4 100 … XXXX Too low

Slide 18

Slide 18 text

These are all too low 1 50 100 Too low

Slide 19

Slide 19 text

Eliminated 25 more 75 51 100 Too high

Slide 20

Slide 20 text

And we eliminated some more 51 63 74 Too low

Slide 21

Slide 21 text

7 STEPS 100 50 25 13 7 4 2 1

Slide 22

Slide 22 text

10 STEPS 1000 -> 500 -> 250 -> 125 -> 63 -> 32 -> 16 -> 8 -> 4 -> 2 -> 1

Slide 23

Slide 23 text

17 STEPS 100,000 -> 50,000 -> 25,000 -> 12,500 -> 6,300 -> 3,150 -> 1,575 -> 788 -> 394 -> 197 -> 99 -> 50 -> 25 -> 13 -> 7 -> 4 -> 2 -> 1

Slide 24

Slide 24 text

22 = 4 23 = 8 24 = 16 25 = 32 26 = 64

Slide 25

Slide 25 text

22 = 4 23 = 8 24 = 16 25 = 32 26 = 64 log2 4 = 2 log2 8 = 3 log2 100 => 6.643 log2 100000 => 16.609

Slide 26

Slide 26 text

* Binary search only works when our list is sorted

Slide 27

Slide 27 text

Searching for a new place to live… Optimal stopping

Slide 28

Slide 28 text

or finding a significant other

Slide 29

Slide 29 text

The secretary problem

Slide 30

Slide 30 text

https://giphy.com/gifs/scooby-doo-wfOe7SdZ3XyHm

Slide 31

Slide 31 text

http://gph.is/15twRiZ

Slide 32

Slide 32 text

37%

Slide 33

Slide 33 text

* When we don’t know all the options, optimal stopping tells us when to stop and make a decision

Slide 34

Slide 34 text

Digging at grandma’s attic Recursion

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

box box container box

Slide 37

Slide 37 text

Make a pile of boxes while the pile is not empty Grab a box if you find a box, add it to the pile of boxes Go back to the pile if you find a diary, you’re done!

Slide 38

Slide 38 text

Go through each item in the box if you find a box… if you find a diary, you’re done!

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

def factorial(x) if x == 1 1 else x * factorial(x-1) end end

Slide 41

Slide 41 text

def factorial(x) if x == 1 1 else x * factorial(x-1) end end

Slide 42

Slide 42 text

def factorial(x) if x == 1 1 else x * factorial(x-1) end end

Slide 43

Slide 43 text

factorial(4) = 4 * factorial(3) factorial(3) = 3 * factorial(2) factorial(2) = 2 * factorial(1) factorial(1) = 1

Slide 44

Slide 44 text

factorial(4) = 4 * factorial(3) factorial(3) = 3 * factorial(2) factorial(2) = 2 * factorial(1) factorial(1) = 1 4 * 3 * 2 * 1 = 24

Slide 45

Slide 45 text

* Recursion can be applied whenever a problem can be solved by dividing it into smaller problems

Slide 46

Slide 46 text

* … and needs a recursion case and a base case

Slide 47

Slide 47 text

Sorting a book shelf Sorting

Slide 48

Slide 48 text

Bubble sort https://giphy.com/gifs/foxhomeent-book-books-3o7btW1Js39uJ23LAA

Slide 49

Slide 49 text

Insertion sort https://giphy.com/gifs/atcqQ5PuX41J6

Slide 50

Slide 50 text

https://imgur.com/Xz3Z2iL Merge sort

Slide 51

Slide 51 text

empty array array with one element No need to sort these arrays 33 Quicksort

Slide 52

Slide 52 text

check if first element is small than the second one, and if it isn’t => switch 4 2

Slide 53

Slide 53 text

pivot 5 2 4 1 3 3

Slide 54

Slide 54 text

3 2 1 5 4

Slide 55

Slide 55 text

3 2 1 5 4 qsort( ) qsort( )

Slide 56

Slide 56 text

3 2 1 5 4 + + 3 2 1 5 4

Slide 57

Slide 57 text

* Should we be sorting at all? https://people.ucsc.edu/~swhittak/papers/chi2011_refinding_email_camera_ready.pdf

Slide 58

Slide 58 text

Getting things done Single machine scheduling

Slide 59

Slide 59 text

There’s nothing so fatiguing as the eternal hanging on of an uncompleted task William James

Slide 60

Slide 60 text

Make goals explicit

Slide 61

Slide 61 text

Strategy: earliest due date

Slide 62

Slide 62 text

https://giphy.com/gifs/nickelodeon-animation-nick-nicktoons-3o7TKTc8NHnZrVFlFm

Slide 63

Slide 63 text

Strategy: Moore’s algorithm

Slide 64

Slide 64 text

http://gifsgallery.com/watermelon+animated+gif?image=323981005

Slide 65

Slide 65 text

Strategy: shortest processing time

Slide 66

Slide 66 text

Client 1: 4 days task Client 2: 1 day task = 5 days of work

Slide 67

Slide 67 text

Client 1: 4 days task = 4 days waiting Client 2: 1 day task = 5 days waiting = 9 days of waiting

Slide 68

Slide 68 text

Client 2: 1 day task = 1 days waiting Client 1: 4 days task = 5 days waiting = 6 days of waiting

Slide 69

Slide 69 text

Shortest processing time Client 2: 1 day task = 1 days waiting Client 1: 4 days task = 5 days waiting = 6 days of waiting Metric: sum of completion times

Slide 70

Slide 70 text

Suppose we want to find a magician Breadth first search

Slide 71

Slide 71 text

Node Node Edge

Slide 72

Slide 72 text

Elle Hannah Caleb Lachlan Keith Schneem Michelle

Slide 73

Slide 73 text

Elle Hannah Caleb Lachlan Keith Schneem Michelle

Slide 74

Slide 74 text

https://vimeo.com/90177460

Slide 75

Slide 75 text

Elle Hannah Caleb Lachlan Keith Schneem Michelle

Slide 76

Slide 76 text

Elle Hannah Caleb Lachlan Keith Schneem Michelle

Slide 77

Slide 77 text

graph = { "elle"=>["hannah", "caleb", "lachlan"], "hannah"=>["michelle", "schneem"], "caleb"=>["schneem"], "lachlan"=>["keith"], "michelle"=>[], "schneem"=>[], "keith"=>[] }

Slide 78

Slide 78 text

graph = { "elle"=>["hannah", "caleb", "lachlan"], "hannah"=>["michelle", "schneem"], "caleb"=>["schneem"], "lachlan"=>["keith"], "michelle"=>[], "schneem"=>[], "keith"=>[] }

Slide 79

Slide 79 text

* Breadth first search works only we search in the same order in which the people (nodes) were added

Slide 80

Slide 80 text

Travelling salesperson

Slide 81

Slide 81 text

Melbourne Geelong Ballarat Frankston Kew Eltham Epping

Slide 82

Slide 82 text

Melbourne Geelong Ballarat Frankston Kew Eltham Epping

Slide 83

Slide 83 text

Melbourne Geelong Ballarat Frankston Kew Eltham Epping

Slide 84

Slide 84 text

* Just relax! by relaxing the constraints, we make it easier to find solutions

Slide 85

Slide 85 text

Building a recommendation system K nearest neighbours

Slide 86

Slide 86 text

A (2,1) B (1,3) C (5,5)

Slide 87

Slide 87 text

A (2,1) B (1,3) X Y (X1 -X2 )2 + (Y1 -Y2 )2 Distance between A to B C (5,5)

Slide 88

Slide 88 text

(1-3)2 + (2- 1)2 A (2,1) C (5,5) B (1,3) X Y Distance between A to B

Slide 89

Slide 89 text

(1-3)2 + (2- 1)2 A (2,1) C (5,5) B (1,3) X Y 22 + 12 Distance between A to B

Slide 90

Slide 90 text

(1-3)2 + (2- 1)2 A (2,1) C (5,5) B (1,3) X Y 22 + 12 4 + 1 K = 2.236 Distance between A to B

Slide 91

Slide 91 text

(5-3)2 + (5- 1)2 A (2,1) C (5,5) B (1,3) X Y Distance between C to B

Slide 92

Slide 92 text

A (2,1) C (5,5) B (1,3) X Y 22 + 42 Distance between C to B (5-3)2 + (5- 1)2

Slide 93

Slide 93 text

A (2,1) C (5,5) B (1,3) X Y 22 + 42 Distance between C to B (5-3)2 + (5- 1)2 4 + 16 K = 4. 472

Slide 94

Slide 94 text

Comedy Action Drama Horror Romance 4 4 5 1 1 5 5 3 2 1 2 1 5 3 5

Slide 95

Slide 95 text

hannah => (4, 4, 5, 1, 1) caleb => (5, 5, 3, 2, 1) lachlan => (2, 1, 5, 3, 5)

Slide 96

Slide 96 text

(4-5)2 + (4-5)2 + (5-3)2 + (1-2)2 + (1- 1)2 hannah => (4, 4, 5, 1, 1) caleb => (5, 5, 3, 2, 1)

Slide 97

Slide 97 text

1 + 1 + 4 + 1 + 0 7 K = 2.64

Slide 98

Slide 98 text

(4-2)2 + (4- 1)2 + (5-5)2 + (1-3)2 + (1-5)2 hannah => (4, 4, 5, 1, 1) lachlan => (2, 1, 5, 3, 5)

Slide 99

Slide 99 text

4 + 9 + 0 + 4 + 16 33 K = 5.74

Slide 100

Slide 100 text

* K-Nearest Neighbours uses feature extraction, which means converting an item into a list of numbers that can be compared

Slide 101

Slide 101 text

Thinking less Overfitting

Slide 102

Slide 102 text

https://www.zmescience.com/other/charles-darwin-marry-or-not/ It being proved necessary to marry

Slide 103

Slide 103 text

The case against complexity

Slide 104

Slide 104 text

If you can’t explain it simply, you don’t understand it well enough. Anonymous

Slide 105

Slide 105 text

Strategies • Regularisation

Slide 106

Slide 106 text

Strategies • Regularisation • Add weight to points

Slide 107

Slide 107 text

Strategies • Regularisation • Add weight to points • Early stopping

Slide 108

Slide 108 text

Strategies • Regularisation • Add weight to points • Early stopping • Stay clear from finer details

Slide 109

Slide 109 text

It is intolerable to think of spending one’s whole life like a neuter bee, working, working, and nothing after all. Charles Darwin

Slide 110

Slide 110 text

When algorithms go wrong https://www.bloomberg.com/view/articles/2017-04-18/united-airlines-exposes-our-twisted-idea-of-dignity

Slide 111

Slide 111 text

https://en.wikipedia.org/wiki/United_Express_Flight_3411_incident

Slide 112

Slide 112 text

Every algorithm reflects the subjective choices of its human designer Cathy O’Neil

Slide 113

Slide 113 text

Elle Meredith @aemeredith