Unary and Binary Great Theoretical Ideas In Computer Science Danny Sleator CS 15-251 Spring 2010 Lecture 3 Jan 19, 2010 Carnegie Mellon University Homework #1 is due today at 11:59pm Give yourself sufficient time to make PDF Quiz #1 is next Thursday during lecture Oh No! More on Fractals Fractals are geometric objects that are self-similar, i.e. composed of infinitely many pieces, all of which look the same. The Koch Family of CurvesFractal Dimension We can break a line segment into N self-similar pieces, and each of which can be magnified by a factor of N to yield the original segment. We can break a square into N2 self-similar pieces, and each of which can be magnified by a factor of N. Fractal Dimension The dimension is the exponent of the number of self-similar pieces with magnification factor into which the figure may be broken. Hausdorff dimension Fractal Dimension of the Plane We can break a square into N2 self-similar pieces, and each of which can be magnified by a factor of N. Fractal Dimension of the Koch Curve We begin with a straight line of length 1 Remove the middle third of the line, and replace it with two lines that each have the same length Repeat infinitelyFractal Dimension of the Koch Curve 1 The Koch Family of Curves 60o What if we increase that angle but keep all sides of the equal length? 72o Compute its dimension! The Koch Family of Curves |AD|= 2 + |BC| 72o 1 A B C D |BC| = 2 cos(72o) The Koch Family of Curves 72o 1 A B C D 90o A B C D Increase this angle Plane-filling curveUnary and Binary How to play the 9 stone game? 9 stones, numbered 1-9 Two players alternate moves. Each move a player gets to take a new stone Any subset of 3 stones adding to 15, wins. 1 2 3 4 5 6 7 8 9 Magic Square: Brought to humanity on the back of a tortoise from the river Lo in the days of Emperor Yu in ancient China 4 923 5 7 8 1 6 Magic Square: Any 3 in a vertical, horizontal, or diagonal line add up to 15.Conversely, any 3 that add to 15 must be on a line. TIC-TAC-TOE on a Magic Square Represents The Nine Stone Game Alternate taking squares 1-9. Get 3 in a row to win. Always seek the more useful one! Don’t stick with the representation in which you encounter problems! This idea requires a lot of practice Basic Idea of This Lecture 1 2 3 4 Prehistoric UnaryYou already used induction to verify that the answer is !n(n+1) Consider the problem of finding a formula for the sum of the first n numbers A different approach… 1 + 2 3 n-1 n S + + … + + = 1 + 2 … n-1 n S + + n-2 + + = n+1 + n+1 … n+1 n+1 2S + + n+1 + + = n(n+1) = 2S 1 + 2 3 n-1 n S + + … + + = 1 + 2 … n-1 n S + + n-2 + + = n(n+1) = 2S 1 2 . . . . . . . . n n . . . . . . . 2 1 There are n(n+1) dots in the grid! nth Triangular Number !n = 1 + 2 + 3 + . . . + n-1 + n = n(n+1)/2nth Square Number ƙn = n2 = !n + !n-1 Breaking a square up in a new way Breaking a square up in a new way 1 Breaking a square up in a new way 1 + 3Breaking a square up in a new way 1 + 3 + 5 Breaking a square up in a new way 1 + 3 + 5 + 7 Breaking a square up in a new way 1 + 3 + 5 + 7 + 9 =? 1 + 3 + 5 + 7 + 9 = 52 Breaking a square up in a new wayPythagoras The sum of the first n odd numbers is n2 Here is an alternative dot proof of the same sum…. ƙn = !n + !n-1 = n2 nth Square Number ƙn = !n + !n-1 = n2 nth Square Numberƙn = !n + !n-1 nth Square Number ƙn = !n + !n-1 = Sum of first n odd numbers nth Square Number We find a formula for the sum of the first n cubes. !n !n=n (n+1)/2 Area of square = (!n)2!n-1 !n-1 ? ? !n !n=n (n+1)/2 Area of square = (!n)2 !n-1 !n-1 n n !n !n=n (n+1)/2 Area of square = (!n)2 !n-1 !n-1 n n !n !n Area of square = (!n)2 !n-1 !n-1 n n !n !n (!n-1)2 n!n-1 n!n Area of square = (!n)2 = (!n-1)2 + n!n-1 + n!n = (!n-1)2 + n(!n-1 + !n) = (!n-1)2 + n(n2) = (!n-1)2 + n3(!n)2 = n3 + (!n-1)2 = n3 + (n-1)3 + (!n-2)2 = n3 + (n-1)3 + (n-2)3 + (!n-3)2 = n3 + (n-1)3 + (n-2)3 + … + 13 (!n)2 = 13 + 23 + 33 + … +n3 = [ n(n+1)/2 ]2 Can you find a formula for the sum of the first n squares? Babylonians needed this sum to compute the number of blocks in their pyramids Rhind Papyrus Scribe Ahmes was Martin Gardner of his day!A man has 7 houses, Each house contains 7 cats, Each cat has killed 7 mice, Each mouse had eaten 7 ears of spelt, Each ear had 7 grains on it. What is the total of all of these? Sum of powers of 7 Rhind Papyrus What is a closed form of the sum of powers of integers? 1 + X1 + X2 + X3 + … + Xn-2 + Xn-1 = X - 1 Xn – 1 We’ll use this fundamental sum again and again: The Geometric Series Proof (X-1) ( 1 + X1 + X2 + X3 + … + Xn-2 + Xn-1 ) X1 + X2 + X3 + … + Xn-1 + Xn = - 1 - X1 - X2 - X3 - … - Xn-2 - Xn-1 = Xn - 1 (when x ! 1) Geometric Series for x=2Geometric Series for x=! Two Case Studies Bases and Representation BASE X Representation S = an-1 an-2 … a1 a0 represents the number: Base 2 [Binary Notation] 101 represents: 1 (2)2 + 0 (21) + 1 (20) Base 7 015 represents: 0 (7)2 + 1 (71) + 5 (70) = = an-1 Xn-1 + an-2 Xn-2 + . . . + a0 X0 Sumerian-Babylonian: 10, 60, 360 Egyptians: 3, 7, 10, 60 Maya: 20 Africans: 5, 10 French: 10, 20 English: 10, 12, 20 Bases In Different CulturesBASE X Representation S = ( an-1 an-2 … a1 a0 )X represents the number: an-1 Xn-1 + an-2 Xn-2 + . . . + a0 X0 Largest number representable in base-X with n “digits” = (X-1 X-1 X-1 X-1 X-1 … X-1)X = (X-1)(Xn-1 + Xn-2 + . . . + X0) = (Xn – 1) k uses …
View Full Document