An Introduction to Graph Theory and a Taste of Recurrences Discrete Math, Preliminary Material for Chapter 13 Key Graph Theory Concepts: Binary Trees and Complete Graphs I. Warm-Up: The Fibonacci Numbers The numbers of the Fibonacci sequence, fn, can be defined as follows: f0 = 1, i.e. the 0th Fibonacci number is 1 f1 = 1, i.e. the 1st Fibonacci number is 1 For k ≥ 2, fk = fk-1 + fk-2, i.e. every other Fibonacci number is the sum of the two Fibonacci numbers preceding it What is f5? Suppose we wanted to find f100. How would we go about doing this? What would we need to know? A Little History (Epp, Boyer) Incidentally, the Fibonacci numbers are named for Leonardo of Pisa, who was known as Fibonacci. In 1202, he posed this problem, which gave rise to what we now call the Fibonacci Sequence: A single pair of rabbits (one male, one female) is born at the beginning of a year. Assume the following conditions: 1. Rabbit pairs are not fertile during their first month of life but thereafter give birth to one new male/female pair at the end of every month. 2. No rabbits die. How many rabbits will there be at the end of the year? II. Recursion and Recurrence Relations The Fibonacci sequence is perhaps the most famous example of what we call a recurrence relation or a definition made using recursion. First Definition: Recursion See recursion. Okay, what's the deal with that definition? Isn't it dancing around the issue? Discuss. Many concepts in mathematics and computer science need to be defined recursively. Think about sequences where, in order to find one term, you need to know the term beforehand. But, in order to know the term beforehand, we need to know the term before that. Then we need to know the term before that… and the term before that and the term before that… So, how do we ever give a complete definition? Where have we seen something like this before? So then, a complete recursive definition has two parts… Definition: Recursive Definition A recursive definition of a concept is a definition that has two parts: 1. Base: A definition of the concept for some starting point, usually an n = 0 or n = 1 term. 2. Recursion: How to get to the next instance of the concept based on previous instances or smaller choices of n. The concept is very related to the concept of induction. In general, we use recursion to define sequences and we use induction to prove claims about recursively defined sequences. When we are talking about sequences, we sometimes use the name recurrence relation: Definition: Recurrence Relation (Epp) A recurrence relation for a sequence a0, a1, a2, … is a formula that relates each term ak to certain of its predecessors ak-1, …, ak-i, where i is fixed and k ≥ i. The initial conditions specify the fixed values of a0, …, ai-1. This definition is nice because it is very general. Most of the time, though, there is only one fixed value or base value. However, nothing prevents us from defining a sequence with multiple base values (consider the two 1s in the Fibonacci sequence), hence the generality with i in the definition above. (Note that there are also two forms of induction to handle this generality. The one we looked at earlier in the year works when we have one base case. There's another form of induction called strong induction that proves claims where there are multiple base cases.) We could spend quite a bit of time studying recurrences by themselves. We'll just scratch the surface and use them a few times in the remainder of the course. Question: Answer: If we have a recurrence relation for a sequence, is it possible to express the sequence in a way that does not use recursion? Sometimes. When we are able to do so, we find what is called the closed form of the recurrence. It is an algebraic formula or a definition that tells us how to find the nth term without needing to know any of the preceding terms. The process of finding the closed form is called solving a recurrence. There are various methods to "solving" recurrence that are used in practice. Each has its place; each has a difference sort of output. Three Methods to Solving Recurrences: 1. Iteration: Start with the recurrence and keep applying the recurrence equation until we get a pattern. (The result is a guess at the closed form.) 2. Substitution: Guess the solution; prove it using induction. (The result here is a proven closed form. It's often difficult to come up the guess blindly though, so, in practice, iteration and substitution are used hand-in-hand.) 3. Master Theorem: Plugging into a formula that gives an approximate bound on the solution. (The result here is only a bound on the closed form. It is not an exact solution.) The Master Theorem formula is rather complicated and requires more background. Thus, it's not something you'll see unless you take advanced computer science courses in college. III. Binary Trees Question: What is a tree? We'll use recursion to define the concept of a binary tree. A binary tree is built up from a series of nodes or vertices. A family tree is a common application of trees; some of the language we'll use comes from there. Definition: Binary Tree 1. Base: An empty tree (no node) is a binary tree. A single node is a binary tree. 2. Recursive: The structure formed by connecting 0, 1, or 2 binary trees by a common node hierarchically above is a binary tree. Examples of Binary Trees: Question: Why is it called a binary tree? We need to be aware of several important terms. We'll look at these visually via an example. Tree terms: root parent children (left child, right child) siblings descendant ancestor Example tree: f d i e a c b g j h Problem: Write a recursive definition for descendant. Two special kinds of binary trees are expression trees and binary search trees. We'll go into more detail on these soon, but for now, let's consider an example of each. Example Expression Tree: Expression tree for a * b + c Example Binary Search Tree: IV. Some Graph Theory: Complete Graphs A binary tree is a general case of a something called a tree, which simply allows a parent to have any number of children. A tree is a special case of what we call a graph. In a tree, you wouldn't want to allow two siblings to be connected. However, in a graph, we allow any kind of connection. It is these connections that make graph theory a very useful area of mathematics. Informal definition of a graph: dots and lines n vertices joined by edges in some fashion Kn is called the complete graph on n vertices. Here every vertex is connected to every other vertex: K1 K2 K3 K4 Question: How do we obtain K5? Problem: Draw K6. Question: Can we find a recurrence for en, the number of edges in Kn? e1 = e2 = Recurrence relation: e3 = e1 = ____ ek = ___________________ e4 = for k _____ e5 = e6 = Question: Now can we find a closed form of en? Guess for the closed form: en = Now, let's prove the closed form correct. In order to prove a closed form of a recurrence, we need to use mathematical induction: To prove: P(n): Proof: Base: Inductive Step: In this example, we completely solved the recurrence by first guessing the closed form using iteration and proving the closed form to be true using substitution. We now have a closed form of the number of edges in a complete graph, but, more importantly, we have a sense of the structure of complete graphs.