Programming's Greatest Hits of the 60s and 70s

Preview:

Citation preview

Programming`s Greatest Hits of the

60s and 70s

Michelle Brush Engineering Director, Cerner Corporation

Chapter Leader, Kansas City Girl Develop It Conference Organizer, Midwest.io

Where  Are  We?

(41.911582,  -­‐87.634803)

Where  Are  We?

(41.911582,  -­‐87.634803)

Latitude:  Y  value

Where  Are  We?

(41.911582,  -­‐87.634803)

Latitude:  Y  value Longitude:  X  value

Assuming  we  have  a  data  store  of  the  locations  of  all  

bars  in  the  world…

https://www.flickr.com/photos/shutterrunner/4334879403/“Today. The Green Door Tavern.” Shutter Runner CC BY 2.0

Let’s find a fun place

nearbyto have a beer.

Interview Question:

Write  an  API  to  support  searching  for  the  nearest  bars.  

     

How would you do it?

Right  Answer

Google  Places  API

Sometimes our job is to find ways to not write code.

Let’s rephrase the question.

Interview Question:

Write  an  API  to  support  searching  for  the  nearest  bars                            

from  scratch.      

How would you do it?

Binary Search2 4 7 9 11 13 34 37 92 1050 1 2 3 4 5 6 7 8 9

?

?

?Found It!

Everyone  used  to  know  binary  search.      

They  just  didn’t  know  what  it  was  called.

(cc)  http://www.recyclethis.co.uk(and picked inefficient pivot points)

SOME SORTING REQUIRED.

INSERT SORT ALGORITHM NOW.

Sort by X, then Y!

Well, that breaks.

Which is closer?

United  Lily  Growers  

in  Smith  River  California  

~1800  miles

The  Green  Door  Tavern  

not  that  far  in  Chicago  

1.26  miles

or  

X gets preferential treatment over Y.

It doesn’t deserve it.

How about brute force?

1. Iterate  over  every  bar.  2. Calculate  the  distance.  3. Sort  by  the  distance.

 

1630 bars in Chicago alone.

Is there a right answer?

Was I just a mean interviewer?

Some people got it right.

Physics Majors

In particular…

Physics  majors  that  care  about  particle  collisions.

Divide  &  Conquer  the  Space

Divide  &  Conquer  the  Space

Divide  &  Conquer  the  Space

Divide  &  Conquer  the  Space

Rules

Quadrants  are  not  always  equal  in  space.  

They  can  be  equal  in  capacity.          

Capacity  =  Number  of  Objects

Center  Point

(X,  Y)

Or  Bounding  Box

(  X1,  Y1  )

(  X2,  Y2  )

Create  a  Tree  of  Nested  Quadrants

Follow  the  Rectangles  Down

Follow  the  Rectangles  Down

Follow  the  Rectangles  Down

Follow  the  Rectangles  Down

1974

Jon L. Bentley & Raphael Finkel

Quad-Trees

1974

Jon L. Bentley (includes buggy implementation of binary search)

Quad-tree is a very good answer.

It can be generalized to more dimensions.

Octrees

WhiteTimberwolf 2010, Schematic drawing of an octree, a data structure of computer science.

37

37

37

37

37

37

37

37

Binary Search2 4 7 9 11 13 34 37 92 1050 1 2 3 4 5 6 7 8 9

?

?

?Found It!

SOME SORTING REQUIRED.

INSERT SORT ALGORITHM NOW.

I have 2 values. I need 1.

Bit Concatenation

(x, y)

(x3x2x1x0, y3y2y1y0)

x3x2x1x0 y3y2y1y0

(9, 3)

(1001, 0011)

10010011

Bit Interleaving

(x, y)

(x3x2x1x0, y3y2y1y0)

x3y3x2y2x1y1x0y0

(9, 3)

(1001, 0011)

10000111

1966

G.M. Morton

Z Order

3 (0,3) (1,3) (2,3) (3,3)

2 (0,2) (1,2) (2,2) (3,2)

1 (0,1) (1,1) (2,1) (3,1)

0 (0,0) (1,0) (2,0) (3,0)

0 1 2 3

3 1010 10

1011 11

1110 14

1111 15

2 1000 8

1001 9

1100 12

1101 13

1 0010 2

0011 3

0110 6

0111 7

0 0000 0

0001 1

0100 4

0101 5

0 1 2 3

3 1010 10

1011 11

1110 14

1111 15

2 1000 8

1001 9

1100 12

1101 13

1 0010 2

0011 3

0110 6

0111 7

0 0000 0

0001 1

0100 4

0101 5

0 1 2 3

Newly created number determines order.

3 1010 10

1011 11

1110 14

1111 15

2 1000 8

1001 9

1100 12

1101 13

1 0010 2

0011 3

0110 6

0111 7

0 0000 0

0001 1

0100 4

0101 5

0 1 2 3

Newly created number determines order.

start

3 1010 10

1011 11

1110 14

1111 15

2 1000 8

1001 9

1100 12

1101 13

1 0010 2

0011 3

0110 6

0111 7

0 0000 0

0001 1

0100 4

0101 5

0 1 2 3

Newly created number determines order.

start

finish

3101010

101111

111014

111115

210008

10019

110012

110113

1 00102

00113

01106

01117

0 00000

00011

01004

01015

0 1 2 3

3101010

101111

111014

111115

210008

10019

110012

110113

1 00102

00113

01106

01117

0 00000

00011

01004

01015

0 1 2 3

3101010

101111

111014

111115

210008

10019

110012

110113

1 00102

00113

01106

01117

0 00000

00011

01004

01015

0 1 2 3

3101010

101111

111014

111115

210008

10019

110012

110113

1 00102

00113

01106

01117

0 00000

00011

01004

01015

0 1 2 3

3101010

101111

111014

111115

210008

10019

110012

110113

1 00102

00113

01106

01117

0 00000

00011

01004

01015

0 1 2 3

3101010

101111

111014

111115

210008

10019

110012

110113

1 00102

00113

01106

01117

0 00000

00011

01004

01015

0 1 2 3

3101010

101111

111014

111115

210008

10019

110012

110113

1 00102

00113

01106

01117

0 00000

00011

01004

01015

0 1 2 3

3101010

101111

111014

111115

210008

10019

110012

110113

1 00102

00113

01106

01117

0 00000

00011

01004

01015

0 1 2 3

3101010

101111

111014

111115

210008

10019

110012

110113

1 00102

00113

01106

01117

0 00000

00011

01004

01015

0 1 2 3

3101010

101111

111014

111115

210008

10019

110012

110113

1 00102

00113

01106

01117

0 00000

00011

01004

01015

0 1 2 3

3101010

101111

111014

111115

210008

10019

110012

110113

1 00102

00113

01106

01117

0 00000

00011

01004

01015

0 1 2 3

3101010

101111

111014

111115

210008

10019

110012

110113

1 00102

00113

01106

01117

0 00000

00011

01004

01015

0 1 2 3

3101010

101111

111014

111115

210008

10019

110012

110113

1 00102

00113

01106

01117

0 00000

00011

01004

01015

0 1 2 3

3101010

101111

111014

111115

210008

10019

110012

110113

1 00102

00113

01106

01117

0 00000

00011

01004

01015

0 1 2 3

3101010

101111

111014

111115

210008

10019

110012

110113

1 00102

00113

01106

01117

0 00000

00011

01004

01015

0 1 2 3

3101010

101111

111014

111115

210008

10019

110012

110113

1 00102

00113

01106

01117

0 00000

00011

01004

01015

0 1 2 3

(0,0)

(1,1)

space-filling curve

Bit-interleaving can be extended to

multiple dimensions.

from space to graphs…

lost in suburbia

Blue Spruce Dr.

Arborwood Ct.

Elmwood St.

Blue Fir Ln.

Go right.

Go right.

19th CenturyCharles Pierre Trémaux

depth-first search

BREADTH-FIRST SEARCH

BREADTH-FIRST SEARCH1950s

BREADTH-FIRST SEARCH1950s

A

B2

C3

2

D4 2

E

4

1

4

My Example Graph

Open List

A

B2

C3

2

D4 2

E

4

1

4

My Example Graph

Open List

A

B2

C3

2

D4 2

E

4

1

4

My Example Graph

sum of all costs to get here

Open List Closed List

A

B2

C3

2

D4 2

E

4

1

4

My Example Graph

sum of all costs to get here

Open List Closed List

A 0

A

Open List Closed List

A 0

A

B2

C3

D4

Open List Closed List

A 0

A

B2

C3

D4

B 2

C 3

D 4

Open List Closed List

B 2

C 3

D 4

A 0

A

B2

C3

2

D4

E

4

My Example Graph

Open List Closed List

C 3

D 4

E 6

A 0

B 2

A

B2

C3

2

D4

E

4

My Example Graph

Open List Closed List

C 3

D 4

E 6

A 0

B 2

A

B2

C3

2

D4 2

E1

4

My Example Graph

Open List Closed List

D 4

E 4

A 0

B 2

C 3

A

B2

C3

2

D4 2

E1

4

My Example Graph

Open List Closed List

E 4 A 0

B 2

C 3D 4A

B2

C3

2

D4 2

E

4

1

4

My Example Graph

Open List Closed List

E 4 A 0

B 2

C 3D 4A

B2

C3

2

D4 2

E

4

1

4

My Example Graph

1956

Edsger W. Djikstra

Djikstra’s Algorithm

Hamilton Richards - manuscripts of Edsger W. Dijkstra, University Texas at Austin

1956

Edsger W. Djikstra

Djikstra’s Algorithm

Hamilton Richards - manuscripts of Edsger W. Dijkstra, University Texas at Austin

1968

Peter Hart, Nils Nilsson, & Bertram Raphael

A*A

Open List Closed List

A

B2

C3

2

D4 2

E

4

1

4

My Example Graph

sum cost to get here plus distance to goal

0

2

2

13

Open List Closed List

A 3

A

B2

C3

D4

My Example Graph

2

2

13

Open List Closed List

B 4

C 4

D 6

A 3

A

B2

C3

D4

My Example Graph

2

2

13

Open List Closed List

A 3

A

B2

C3

2

D4

E

4

My Example Graph

0

2

2

13

B 4

C 4

D 6

Open List Closed List

A 3

B 4

A

B2

C3

2

D4

E

4

My Example Graph

0

2

2

13

C 4

D 6

E 6

Open List Closed List

A

B2

C3

2

D4 2

E1

4

My Example Graph

0

2

2

13

A 3

B 4

C 4

D 6

E 6

Open List Closed List

A

B2

C3

2

D4 2

E1

4

My Example Graph

0

2

2

13

A 3

B 4

C 4

E 4

D 6

Open List Closed List

A

B2

C3

2

D4 2

E1

4

My Example Graph

0

2

2

13

A 3

B 4

C 4

E 4

D 6

We didn’t have to close D.

Breadth-first Search

Breadth-first Search

Djikstra’s Algorithm

Breadth-first Search

Djikstra’s Algorithm

A*

The power of heuristics.

Breadth-first Search

Djikstra’s Algorithm

A*

Are all edge weights equal?

What’s your most expensive operation?

Do you have insights about your target?

Breadth-First

Djikstra

A*

yes

no

visitshe

uristic

s

?

?

?

breadth-first search f(x) = c

djikstra’s algorithm f(x) = g(x) + c

a* f(x) = g(x) + h(x) + c

The others were specializations.

and we can do more than search with graphs…

1974

Charles L. Forgy

Rete

Premise 1

Premise 2

Premise 3

Conclusion

Rules

Premise 1

Premise 2

Premise 3

Take Action

Rules

(Premise 1, Premise 2, Premise 3)

(Action)

=>

(Premise 1, Premise 2, Premise 3)

(Action)

=>Left Hand Side

(Premise 1, Premise 2, Premise 3)

(Action)

=>Left Hand Side

Right Hand Side

A

B

C

D

ERules are a

directed acyclic graph.

like a trie

C

I OH

I DT

C EY

A K

G E

O N

Root Node

Root Node

Type Nodes

Root Node

Selection Nodes

Type Nodes

Root Node

Negation Nodes

Selection Nodes

Type Nodes

Root Node

Join Nodes

Negation Nodes

Selection Nodes

Type Nodes

Root Node

Terminal Nodes

Join Nodes

Negation Nodes

Selection Nodes

Type Nodes

Root Node

Alpha Memory

Terminal Nodes

Join Nodes

Negation Nodes

Selection Nodes

Type Nodes

Root Node

Beta Memory

Alpha Memory

Terminal Nodes

Join Nodes

Negation Nodes

Selection Nodes

Type Nodes

recommend-diet-changes

Hypertension (severity == moderate)

Demographics (age > 60)

prescribe-bp-meds

Hypertension

HypertensionDemographics

Hypertension (severity == moderate)

Ryan Brush “Retaking Rules for Developers”

Hypertension

Demographics Hypertension (severity == moderate)

Demographics (age > 60)

recommend-diet-changes

prescribe-bp-meds

Ryan Brush “Retaking Rules for Developers”

Sometimes our job is to find ways to not write code.

Let’s not build an expert system!

Let’s not build an expert system!

Let’s not build an expert system!

(-­‐>clara)

Let’s not build an expert system!

(-­‐>clara)

+

=

(-­‐>clara)

+

=

Triskel99 - Own work AMC Pacer, photographed during August 2009.

Efficacy

Cost

Convenience

import  java.util.Comparator;  

public  class  ChoiceComparator  implements  Comparator<Choice>  {  

       @Override          public  int  compare(Choice  o1,  Choice  o2)  {                if(  o2.getEfficacy()  ==  o1.getEfficacy)  {                        if(  o2.getCost()  ==  o1.getCost)  {                                return  o2.getConvenience()  -­‐  o1.getConvenience();                        }                          return  o2.getCost()  -­‐  o1.getCost();                }                return  o2.getEfficacy()  -­‐  o2.getEfficacy();          }  }  

import  java.util.Comparator;  

public  class  ChoiceComparator  implements  Comparator<Choice>  {  

       @Override          public  int  compare(Choice  o1,  Choice  o2)  {                if(  o2.getEfficacy()  ==  o1.getEfficacy)  {                        if(  o2.getCost()  ==  o1.getCost)  {                                return  o2.getConvenience()  -­‐  o1.getConvenience();                        }                          return  o2.getCost()  -­‐  o1.getCost();                }                return  o2.getEfficacy()  -­‐  o2.getEfficacy();          }  }  

public  class  EfficacyComparator  implements  Comparator<Choice>  

public  class  CostComparator  implements  Comparator<Choice>  

public  class  ConvenienceComparator  implements  Comparator<Choice>  

1.SORT  2.TAKE  10  3.GOTO  1

public  class  EfficacyComparator  implements  Comparator<Choice>  

public  class  CostComparator  implements  Comparator<Choice>  

public  class  ConvenienceComparator  implements  Comparator<Choice>  

1.SORT  2.TAKE  10  3.GOTO  1

1974

Jon L. Bentley & Raphael Finkel

Quad-Trees

1966

G.M. Morton

Z Order

for(int i = 0; i < count1; ++i) { for(int j = 0; j < count2; ++j) { for(int k = 0; k < count3; ++k) { for(int l = 0; l < count4; ++l) { for(int m = 0; m < count5; ++m) { for(int n = 0; n < count6; ++n) { for(int o = 0; o < count7; ++o) { for(int p = 0; p < count8; ++p) { for(int q = 0; q < count9; ++q) { for(int r = 0; r < count10; ++r) { for(int s = 0; s < count 11 for(int t = 0; t < count for(int u = 0; for(int v = 0 for(int w for(i fo

for-nado?

You are using the wrong algorithm.

Crack open an algorithms book.

Do a Depth-First Search of Wikipedia

Do a Depth-First Search of Wikipedia

Your solution is out there.

BLOOM FILTER

trie

Gale Shapley

A*

R-Tree

TREAP

Dijkstra’s

Floyd Warshall

D* Hu

ffm

anID

3

CARTRet

e

And  to  be  honest…

It  is  probably  from  the  60s  or  70s.

1979Engineering Director, Cerner Corporation Chapter Leader, Kansas City Girl Develop It Conference Organizer, Midwest.io

@michellebrush

Michelle Brush

Recommended