Beruflich Dokumente
Kultur Dokumente
An Interesting Peruse
WSJ: Best and Worst Jobs of !" #
htt$:%%online&'s(&co)%article%SB"!!!"* *!+ ,! -!-,, .!*+,,--/ -!"- 0!+ ,/&ht)l
Recursive Proble)3Solving
if (problem is sufficiently simple) { Directly solve the problem. Return the solution. } else { Split the problem up into one or more smaller problems with the same structure as the original. Solve each of those smaller problems. Combine the results to get the overall solution. Return the overall solution. }
Parking Rando)ly
Parking Rando)ly
Parking Rando)ly
Parking Rando)ly
Parking Rando)ly
x+1
Parking Rando)ly
x+1
Parking Rando)ly
x+1
Parking Rando)ly
int parkRandomly(double low, double high) { if (high - low < 1.0) { return 0; } else { double x randomReal(low, high - 1.0); return 1 ! parkRandomly(low, x) ! re"urn 1 ! parkRandomly(x ! 1, high); } }
So What4
The beauty of our algorith) is the follo'ing recursive insight: Split an area into smaller, independent pieces and solve each piece separately.
Fig. 11: Three real Mondrian paintings, and three samples from our targeting function. Can you tell which is which?
Source: Jerry O. Talton, Yu ou, Ste!e esser, Jared "u#e, $adom%r M&ch, and 'ladlen (oltun, )Metropolis *rocedural Modeling,+ ACM Transactions on Graphics, ,pril -.//.
6enerating 5ondrians
getWindowWidth()
$et#rns the width of the graphics window.
getWindowHeight()
$et#rns the height of the graphics window.
Many more functions e0ist in the graphics.h interface, which is descri1ed on the we1 site.
Slides by Eric Roberts
9ra'ing Rectangles
drawRect(x, y, width, height)
Draws the o#tline of a rectangle with the specified %o#nds.
setColor(color)
'ets the pen color to the specified color string (s#ch as " L!C"" or "R#$")
setColor("%rrggbb")
'ets the red(green(%l#e components to the specified hexadecimal )al#es.
;ractal Trees
6ro' in so)e direction for a $eriod of ti)e& Then2 s$lit and gro' t'o s)aller trees out'ard at so)e angle&
5ore Trees
What if 'e change the a)ount of branching4 What if 'e )ake the lines thicker4 What if 'e allo' the tree to kee$ gro'ing after it branches4 Stanford Dryad $rogra) uses a co)bination of recursion2 )achine learning2 and hu)an feedback to design aesthetically $leasing trees&
<=haustive Recursion
7o))only2 you 'ill need to generate all ob(ects )atching so)e criteria&
Word 8adders: 6enerate all 'ords that differ by e=actly one letter&
:ften2 structures can be generated iteratively& In )any cases2 ho'ever2 it is best to think about generating all o$tions recursively&
Subsets
>!2 "2 ? @ >!2 "2 2 -2 *2 +? >dikdik2 ibe=? @ >dikdik2 ibe=? > A2 62 72 T ? @ > A2 B2 72 92 <2 A2 B ? > ? @ >a2 b2 c? >?@>?
6enerating Subsets
5any i)$ortant $roble)s in co)$uter science can be solved by listing all the subsets of a set S and finding the best# one out of every o$tion& <=a)$le:
Cou have a collection of sensors on an autono)ous vehicle2 each of 'hich has data co)ing in& Which subset of the sensors do you choose to listen to2 given that each takes a different a)ount of ti)e to read4
6enerating Subsets
6enerating Subsets
6enerating Subsets
6enerating Subsets
6enerating Subsets
6enerating Subsets
6enerating Subsets
The only subset of an e)$ty set is the e)$ty set itself& :ther'ise:
;i= so)e ele)ent x of the set& 6enerate all subsets of the set for)ed by re)oving x fro) the )ain set& These subsets are subsets of the original set& All of the sets for)ed by adding x into those subsets are subsets of the original set&
{ }
{#}, { }
{ }
{#}, { }
{ }