Solving Linear Recurrence Relations (8.2)

Similar documents
DEFINITION OF GRAPH GRAPH THEORY GRAPHS ACCORDING TO THEIR VERTICES AND EDGES EXAMPLE GRAPHS ACCORDING TO THEIR VERTICES AND EDGES

(Refer Slide Time: 01.26)

Last week: Breadth-First Search

Today. Types of graphs. Complete Graphs. Trees. Hypercubes.

Introduction to Graph Theory

UCSD CSE 21, Spring 2014 [Section B00] Mathematics for Algorithm and System Analysis

γ(ɛ) (a, b) (a, d) (d, a) (a, b) (c, d) (d, d) (e, e) (e, a) (e, e) (a) Draw a picture of G.

(5.2) 151 Math Exercises. Graph Terminology and Special Types of Graphs. Malek Zein AL-Abidin

CPSC 536N: Randomized Algorithms Term 2. Lecture 10

Clustering Using Graph Connectivity

CPCS Discrete Structures 1

1 Leaffix Scan, Rootfix Scan, Tree Size, and Depth

Lecture 4: examples of topological spaces, coarser and finer topologies, bases and closed sets

MITOCW watch?v=tkwnms5irbu

Graphs. Introduction To Graphs: Exercises. Definitions:

Discrete Mathematics for CS Spring 2008 David Wagner Note 13. An Introduction to Graphs

Student name: Student ID: MATH 61 (Butler) Midterm II, 12 November 2008

CS 171: Introduction to Computer Science II. Quicksort

CS 4349 Lecture October 18th, 2017

1. Suppose you are given a magic black box that somehow answers the following decision problem in polynomial time:

17/05/2018. Outline. Outline. Divide and Conquer. Control Abstraction for Divide &Conquer. Outline. Module 2: Divide and Conquer

Discrete Mathematics and Probability Theory Fall 2013 Vazirani Note 7

CHAPTER 2. Graphs. 1. Introduction to Graphs and Graph Isomorphism

CSE 101, Winter Discussion Section Week 1. January 8 - January 15

Math 575 Exam 3. (t). What is the chromatic number of G?

Table of Laplace Transforms

EECS 203 Spring 2016 Lecture 8 Page 1 of 6

Ma/CS 6b Class 5: Graph Connectivity

Trees. 3. (Minimally Connected) G is connected and deleting any of its edges gives rise to a disconnected graph.

This chapter covers recursive definition, including finding closed forms.

Discrete Mathematics and Probability Theory Fall 2009 Satish Rao,David Tse Note 8

Lecture 7. s.t. e = (u,v) E x u + x v 1 (2) v V x v 0 (3)

Introduction to Graphs

1 Variations of the Traveling Salesman Problem

Distributed Algorithms 6.046J, Spring, Nancy Lynch

CSE 331: Introduction to Algorithm Analysis and Design Graphs

Binary Decision Diagrams

Chapter 23. Minimum Spanning Trees

CS 561, Lecture 9. Jared Saia University of New Mexico

Induction Review. Graphs. EECS 310: Discrete Math Lecture 5 Graph Theory, Matching. Common Graphs. a set of edges or collection of two-elt subsets

On Covering a Graph Optimally with Induced Subgraphs

CMPSCI 311: Introduction to Algorithms Practice Final Exam

Kruskal s MST Algorithm

Programming and Data Structure

Minimum Spanning Trees

1 Minimum Cut Problem

Lecture 19 Thursday, March 29. Examples of isomorphic, and non-isomorphic graphs will be given in class.

Introduction III. Graphs. Motivations I. Introduction IV

Design and Analysis of Algorithms Prof. Madhavan Mukund Chennai Mathematical Institute

Figure 4.1: The evolution of a rooted tree.

Advanced algorithms. topological ordering, minimum spanning tree, Union-Find problem. Jiří Vyskočil, Radek Mařík 2012

Section 8.2 Graph Terminology. Undirected Graphs. Definition: Two vertices u, v in V are adjacent or neighbors if there is an edge e between u and v.

(Re)Introduction to Graphs and Some Algorithms

Discrete Structures CISC 2315 FALL Graphs & Trees

Approximation slides 1. An optimal polynomial algorithm for the Vertex Cover and matching in Bipartite graphs

U.C. Berkeley CS170 : Algorithms, Fall 2013 Midterm 1 Professor: Satish Rao October 10, Midterm 1 Solutions

We can use a max-heap to sort data.

MATH20902: Discrete Maths, Solutions to Problem Set 1. These solutions, as well as the corresponding problems, are available at

Algorithms: Lecture 7. Chalmers University of Technology

Lecture 4: September 11, 2003

(Refer Slide Time: 05:25)

Basic Combinatorics. Math 40210, Section 01 Fall Homework 4 Solutions

15 Graph Theory Counting the Number of Relations. 2. onto (surjective).

CSE 421 Greedy Alg: Union Find/Dijkstra s Alg

Complete Cototal Domination

Lecture 3 February 9, 2010

Adjacent: Two distinct vertices u, v are adjacent if there is an edge with ends u, v. In this case we let uv denote such an edge.

CSE 2123 Recursion. Jeremy Morris

2. CONNECTIVITY Connectivity

Recursion defining an object (or function, algorithm, etc.) in terms of itself. Recursion can be used to define sequences

Lecture 6: Sequential Sorting

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science Algorithms For Inference Fall 2014

Introduction to Algorithms / Algorithms I Lecturer: Michael Dinitz Topic: Shortest Paths Date: 10/13/15

Master Theorem, Introduction to Graphs

GRAPHS, GRAPH MODELS, GRAPH TERMINOLOGY, AND SPECIAL TYPES OF GRAPHS

Matching Algorithms. Proof. If a bipartite graph has a perfect matching, then it is easy to see that the right hand side is a necessary condition.

Lecture 8: The Traveling Salesman Problem

Crossing bridges. Crossing bridges Great Ideas in Theoretical Computer Science. Lecture 12: Graphs I: The Basics. Königsberg (Prussia)

Lecture 2 : Counting X-trees

Recursive definition of sets and structural induction

Graphs V={A,B,C,D,E} E={ (A,D),(A,E),(B,D), (B,E),(C,D),(C,E)}

Trees. Arash Rafiey. 20 October, 2015

Eulerian Tours and Fleury s Algorithm

Approximation Algorithms

Encoding/Decoding, Counting graphs

1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1

Divide & Conquer. 2. Conquer the sub-problems by solving them recursively. 1. Divide the problem into number of sub-problems

CS 373: Combinatorial Algorithms, Spring 1999

Some Hardness Proofs

Problem Set 2 Solutions

MergeSort, Recurrences, Asymptotic Analysis Scribe: Michael P. Kim Date: April 1, 2015

Recursively Defined Functions

Lecture 22 Tuesday, April 10

1 Definition of Reduction

DESIGN AND ANALYSIS OF ALGORITHMS

Graphs. CS16: Introduction to Data Structures & Algorithms Spring 2018

Definition: A graph G = (V, E) is called a tree if G is connected and acyclic. The following theorem captures many important facts about trees.

Algorithms Exam TIN093/DIT600

DIVIDE & CONQUER. Problem of size n. Solution to sub problem 1

Fast algorithms for max independent set

Transcription:

EECS 203 Spring 2016 Lecture 18 Page 1 of 10 Review: Recurrence relations (Chapter 8) Last time we started in on recurrence relations. In computer science, one of the primary reasons we look at solving a recurrence relation is because many algorithms, whether really recursive or not (in the sense of calling themselves over and over again) often are implemented by breaking the problem down into smaller parts and solving those. In order to get a solid sense of their runtime, we need to be able to either solve the relation or at least get a sense of its complexity (think big-o). Recall the Towers of Hanoi problem (moving discs) and it s solution: Define T(n) = number of moves when there are n discs. T(1) = 1 T(n) = 2T(n-1) + 1 In class last time we guessed at the solution and used an inductive proof to show that the guess (that T(n)=2 n -1) was correct. Today we are going to look at how to find closed form solutions to these problems generally. Last time we worked through solving linear, homogeneous, recurrence relations with constant coefficients of degree 2 Solving Linear Recurrence Relations (8.2) The recurrence is linear because the all the a n terms are just the terms (not raised to some power nor are they part of some function). So a n=2a n-1 is linear but a n=2(a n-1) 2 is not. It is homogeneous because all terms are multiples of some previous value of a n. So a n=2a n-1 is homogeneous, but a n=2a n-1+1 is not. It is of degree k because a n is expressed in terms of the last k terms of the sequence. And it has constant coefficients because all the c terms are constants (not a function of n). We claimed (without proof) that finding the characteristic equation would help. Now, if we divide both sides of this equation by r n-k and move the things around a bit, we get:

EECS 203 Spring 2016 Lecture 18 Page 2 of 10 Some new examples: Indicate if the following are linear, homogeneous and have constant coefficients. If they are, find the characteristic equation associated with the recursion. 1. a n=2a n-1+a n-2 2. a n=a n-1+a n-2+4 3. a n=2a n-1-4a n-2 4. a n=a n-2+a n-3 5. a n=na n-1+a n-2 Working with LH RR with CC and degree 2 That feels like it jumps out of nowhere. Let s focus on what it says, time allowing we will try to show it makes sense (or at least a bit of sense). The proof is on pages 515 and 516 of the text. Consider the Fibonacci sequence defined by a n=a n-1+a n-2. This is saying we need to find the roots of the characteristic equation and then the solution for this relation is of the form, where r 1 and r 2 are those roots. Notice that α is just an arbitrary constant (that we d have to figure out ) Last time we worked out examples 3 and 4 from the text. Let s try this one: an=3an-1-2an-2; a0=3, a1=4

EECS 203 Spring 2016 Lecture 18 Page 3 of 10 Repeated roots Let s do a n=6a n-1-9a n-2 where a 0=1 and a 1=6 What is the characteristic equation? What are the roots of the characteristic equation? What is the solution to the recurrence? General form for arbitrary degree In this class, we will only be working with relations of this type of degree 2. But there is a more general result.

EECS 203 Spring 2016 Lecture 18 Page 4 of 10 Again, we aren t going to worry about this general case, but I want you aware it exists. Linear Nonhomogeneous Recurrence Relations with Constant Coefficients Consider (the fairly common) case of a nonhomogeneous relation. That is, we add something that isn t a term of a n but might be a function of n. So order to solve this, we are going to take three steps:. In Solve the associated homogeneous recurrent relation (that is the one that doesn t have that F(n) term!) Find a particular solution based on F(n). Add those two results. We know how to do the first thing. And finding the particular solution in general can be annoying, but for most polynomials we can make progress as follows: In the general case, we ll have the situation that s=1. But that means we need to watch out if the homogeneous solution has a root that is 1 (which seems to happen a lot more than you d expect). Worked Example (Towers of Hanoi) Let s compute a n=2a n-1 +1 with a 1=1 (recall this is what we had for Towers of Hanoi). The associated HRR is r-2=0, so r=2. So the homogeneous part is 2 n. Now we need the particular part. When dealing with the particular solution F(n)=1*1 n, so s doesn t share a root with the characteristic equation (1 2). So our solution is of the form p 0 (a constant). Thus we ve got a n=2 n +p 0. Solving for the

EECS 203 Spring 2016 Lecture 18 Page 5 of 10 initial case we get a 0=1=2 0 +p 0. So p 0=-1. And we ve now found, rather than guessed, the closed form for the recurrence relation for Towers of Hanoi. Divide and Conquer and the associated recurrence relations (8.3) Let s look at a few fun algorithms that are what we call divide and conquer -type algorithms. We introduced a binary search algorithm in Section 3.1. This binary search algorithm reduces the search for an element in a search sequence of size n to the binary search for this element in a search sequence of size n/2, when n is even. (Hence, the problem of size n has been reduced to one problem of size n/2.) Two comparisons are needed to implement this reduction (one to determine which half of the list to use and the other to determine whether any terms of the list remain). (page 528) If f(n) is the run time to find an element in a sorted list of n elements (assume n is a power of 2), how many comparisons do we need? Write this as a recurrence relation. Consider a merge sort where we split the list in half, sort each half, and then merge the two sorted lists. What is the recurrence relation that describes the runtime of this algorithm? Assume it takes n steps to merge two lists each of size (n/2) i i Why is n a reasonable number of steps to merge two sorted lists of size n/2 into a sorted list of n items?

EECS 203 Spring 2016 Lecture 18 Page 6 of 10 The Master Theorem As we often don t care about specific values, just the order of the complexity of the algorithm, we can generally get away without solving these recurrence relations we are instead happy if we know the order of the solution. And it turns out, there is a plug-and-chug way to do this: The Master Theorem. Examples 1. Using the above, what are the values of a, b, c and d for the binary search algorithm? What is that algorithm s complexity? 2. Using the above, what are the values of a, b, c and d for the merge sort algorithm? What is that algorithm s complexity? 3. Consider the relation F(N)=3F(N/3)+N (which is a merge sort split into 3 parts).

EECS 203 Spring 2016 Lecture 18 Page 7 of 10 A graph G=(V,E) consists of: a non-empty set V of vertices (or nodes) a set E of edges Each edge is associated with two vertices (possibly equal). In a directed graph: all edges are directed. Undirected graph: all edges are undirected. Mixed graph: some of each. Some graphs:

EECS 203 Spring 2016 Lecture 18 Page 8 of 10 Basic Terminology Vertices u and v are adjacent if they are connected by an edge e o In an undirected graph: e = {u,v} o In a directed graph: e = (u,v) The degree of a vertex deg(v) is the number of edge-ends incident to it. o A self-loop edge is counted twice. o In a directed graph, distinguish: in-degree deg (v): number of incoming edges out-degree deg+(v): number of outgoing edges A subgraph of a graph G = (V,E) is a graph H = (W,F) where W V and F E. o A subgraph H is a proper subgraph if H G. The union of two simple graphs G1 = (V1, E1) and G2 = (V2, E2) is the simple graph with vertex set V1 V2 and edge set E1 E2. o The union of G1 and G2 is denoted by G1 G2. Two vertices u and v in an undirected graph G are called adjacent (or neighbors) in G if u and v are endpoints of an edge e of G. Such an edge e is called incident with the vertices u and v and e is said to connect u and v. The set of all neighbors of a vertex v of G = (V,E), denoted by N(v), is called the neighborhood of V. If A is a subset of V, we denote by N(A) the set of all vertices in G that are adjacent to at least one vertex in A. Examples and Questions: 1. What is the degree of each node? 2. Draw the graph A=(V,E) where V={a, b, c, d}, E={{a,b}, {b,d}} 3. Draw the graph B=(V,E) where V={a, b, c, d}, E={{a,b}, {d,b}, {c,a}} 4. We now have 4 graphs total (A, B, G, H). Are any of them subgraphs of the other? 5. Draw the graph X=(V,E) where V={a, b, c, d}, E={(a,b), (b,d)}

EECS 203 Spring 2016 Lecture 18 Page 9 of 10

EECS 203 Spring 2016 Lecture 18 Page 10 of 10