Presentation is loading. Please wait.

Presentation is loading. Please wait.

Week 11 - Friday.  What did we talk about last time?  Graph isomorphism  Trees.

Similar presentations


Presentation on theme: "Week 11 - Friday.  What did we talk about last time?  Graph isomorphism  Trees."— Presentation transcript:

1 Week 11 - Friday

2  What did we talk about last time?  Graph isomorphism  Trees

3

4  You are the despotic ruler of an ancient empire  Tomorrow is the 25th anniversary of your reign  You have 1,000 bottles of wine you were planning to open for the celebration  Your Grand Vizier uncovered a plot to murder you:  10 years ago, a rebel worked in the vineyard that makes your wine  He poisoned one of the 1,000 bottles you are going to serve tonight and has been waiting for revenge  The rebel died an accidental death, and his papers revealed his plan, but not which bottle was poisoned  The poison exhibits no symptoms until death  Death occurs within ten to twenty hours after consuming even the tiniest amount of poison  You have over a thousand slaves at your disposal and just under 24 hours to determine which single bottle is poisoned  You have a few hundred prisoners, sentenced to death  Can you use just the prisoners and risk no slaves?  If so, what's the smallest number of prisoners you can risk and still be sure to find the bottle?

5

6  A grammar for a formal language (such as we will discuss next week or the week after) is made up of rules that allow non- terminals to be turned into other non-terminals or terminals  For example: 1.  2.  | 3.  4.  a | an | the 5.  funky 6.  DJ | beat 7.  plays | spins  Make a parse tree corresponding to the sentence, "The DJ plays a funky beat"

7  Any tree with more than one vertex has at least one vertex of degree 1  If a vertex in a tree has degree 1 it is called a terminal vertex (or leaf)  All vertices of degree greater than 1 in a tree are called internal vertices (or branch vertices)

8  For any positive integer n, a tree with n vertices must have n – 1 edges  Prove this by mathematical induction  Hint: Any tree with 2 or more nodes has a vertex of degree 1. What happens when you remove that vertex?

9  In a rooted tree, one vertex is distinguished and called the root  The level of a vertex is the number of edges along the unique path between it and the root  The height of a rooted tree is the maximum level of any vertex of the tree  The children of any vertex v in a rooted tree are all those nodes that are adjacent to v and one level further away from the root than v  Two distinct vertices that are children of the same parent are called siblings  If w is a child of v, then v is the parent of w  If v is on the unique path from w to the root, then v is an ancestor of w and w is a descendant of v

10  Consider the following tree, rooted at 0  What is the level of 5?  What is the level of 0?  What is the height of this tree?  What are the children of 3?  What is the parent of 2?  What are the siblings of 8?  What are the descendants of 3? 3 3 0 0 5 5 2 2 1 1 7 7 9 9 6 6 4 4 8 8

11  A binary tree is a rooted tree in which every parent has at most two children  Each child is designated either the left child or the right child  In a full binary tree, each parent has exactly two children  Given a parent v in a binary tree, the left subtree of v is the binary tree whose root is the left child of v  Ditto for right subtree

12  As we all know from data structures, a binary tree can be used to make a data structure that is efficient for insertions, deletions, and searches  But, it doesn't stop there!  We can represent binary arithmetic with a binary tree  Make a binary tree for the expression ((a – b)∙c) + (d/e)  The root of each subtree is an operator  Each subtree is either a single operand or another expression

13  If k is a positive integer and T is a full binary tree with k internal vertices, then T has a total of 2k + 1 vertices and has k + 1 terminal vertices  Prove it!  Hint: Induction isn't needed. We just need to relate the number of non-terminal nodes to the number of terminal nodes

14  If T is a perfect binary tree with height h, then it has 2 h+1 – 1 vertices  Prove it using induction!

15  If T is a binary tree with t terminal vertices and height h, then t  2 h  Prove it using strong induction on the height of the tree  Hint: Consider cases where the root of the tree has 1 child and 2 children separately

16

17  I am assuming that you have been graphing functions since about 6 th or 7 th grade  Still, the formal definition of a graph of a function is:  Let f be a real-valued function of a real variable  The graph of f is the set of all points (x, y) in the Cartesian coordinate plane such that x is in the domain of f and y = f(x)

18  In computer science, we are often interested in power functions of x written p a (x) where p a (x) = x a where x and a are nonnegative  Power functions are the building blocks of polynomial functions  Graph the following on the same coordinate axes p0p0  p 1/2 p1p1 p2p2

19  Recall the definition of the floor of x:   x  = the largest integer that is less than or equal to x  Graph f(x) =  x   Defining functions on integers instead of real values affects their graphs a great deal  Graph p 1 (x) = x, x  R  Graph f(n) = n, n  N

20  There is a strong visual (and of course mathematical) correlation a function that is the multiple of another function  Examples:  g(x) = x + 2  2g(x) = 2x + 4  Given f graphed below, sketch 2f -6 -5 -4 -3 -2 -1 1 2 3 4 5 6 2121 -2

21  Consider the absolute value function  f(x) = |x|  Left of the origin it is constantly decreasing  Right of the origin it is constantly increasing -6 -5 -4 -3 -2 -11 2 3 4 5 6 2121 -2

22  We say that f is decreasing on the set S iff for all real numbers x 1 and x 2 in S, if x 1 f(x 2 )  We say that f is increasing on the set S iff for all real numbers x 1 and x 2 in S, if x 1 < x 2, then f(x 1 ) < f(x 2 )  We say that f is an increasing (or decreasing) function iff f is increasing (or decreasing) on its entire domain  Clearly, a positive multiple of an increasing function is increasing  Virtually all running time functions are increasing functions

23 Student Lecture

24

25  Mathematicians worry about the growth of various functions  They usually express such things in terms of limits, maybe with derivatives  We are focused primarily on functions that bound running time spent and memory consumed  We just need a rough guide  We want to know the order of the growth

26  Let f and g be real-valued functions defined on the same set of nonnegative real numbers  f is of order at least g, written f(x) is  (g(x)), iff there is a positive A  R and a nonnegative a  R such that  A|g(x)| ≤ |f(x)| for all x > a  f is of order at most g, written f(x) is O(g(x)), iff there is a positive B  R and a nonnegative b  R such that  |f(x)| ≤ B|g(x)| for all x > b  f is of order g, written f(x) is  (g(x)), iff there are positive A, B  R and a nonnegative k  R such that  A|g(x)| ≤ |f(x)| ≤ B|g(x)| for all x > k

27  Express the following statements using appropriate notation:  10|x 6 | ≤ |17x 6 – 45x 3 + 2x + 8| ≤ 30|x 6 |, for x > 2    Justify the following:  is  (  x)

28  Let f and g be real-valued functions defined on the same set of nonnegative real numbers 1. f(x) is  (g(x)) and f(x) is O(g(x)) iff f(x) is  (g(x)) 2. f(x) is  (g(x)) iff g(x) is O(f(x)) 3. f(x) is  (f(x)), f(x) is O(f(x)), and f(x) is  (f(x)) 4. If f(x) is O(g(x)) and g(x) is O(h(x)) then f(x) is O(h(x)) 5. If f(x) is O(g(x)) and c is a positive real, then c  f(x) is O(g(x)) 6. If f(x) is O(h(x)) and g(x) is O(k(x)) then f(x) + g(x) is O(G(x)) where G(x) = max(|h(x)|,|k(x)|) for all x 7. If f(x) is O(h(x)) and g(x) is O(k(x)) then f(x)g(x) is O(h(x)k(x))

29  If 1 < x, then  x < x 2  x 2 < x 3 ……  So, for r, s  R, where r 1,  x r < x s  By extension, x r is O(x s )

30  Prove a  bound for g(x) = (1/4)(x – 1)(x + 1) for x  R  Prove that x 2 is not O(x)  Hint: Proof by contradiction

31  Let f(x) be a polynomial with degree n  f(x) = a n x n + a n-1 x n-1 + a n-2 x n-2 … + a 1 x + a 0  By extension from the previous results, if a n is a positive real, then  f(x) is O(x s ) for all integers s  n  f(x) is  (x r ) for all integers r ≤ n  f(x) is  (x n )  Furthermore, let g(x) be a polynomial with degree m  g(x) = b m x m + b m-1 x m-1 + b m-2 x m-2 … + b 1 x + b 0  If a n and b m are positive reals, then  f(x)/g(x) is O(x c ) for real numbers c > n - m  f(x)/g(x) is not O(x c ) for all integers c > n - m  f(x)/g(x) is  (x n - m )

32

33  More on asymptotic notation

34  Keep reading Chapter 11  Keep working on Assignment 9  Due next Friday


Download ppt "Week 11 - Friday.  What did we talk about last time?  Graph isomorphism  Trees."

Similar presentations


Ads by Google