22C:19 Discrete Structures Advanced Counting Spring 2014 Sukumar Ghosh.

Slides:



Advertisements
Similar presentations
Analysis of Algorithms II
Advertisements

Dynamic Programming ACM Workshop 24 August Dynamic Programming Dynamic Programming is a programming technique that dramatically reduces the runtime.
CSE 211- Discrete Structures
Recursion and Induction
Advanced Counting Techniques
Chapter Recurrence Relations
Discrete Mathematics 3. MATRICES, RELATIONS, AND FUNCTIONS Lecture 5 Dr.-Ing. Erwin Sitompul
Finite-state Recognizers
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Chapter 6 The Relational Algebra.
Equivalence Relations
Fall 2002CMSC Discrete Structures1 Now it’s Time for… RecurrenceRelations.
22C:19 Discrete Math Relations Fall 2010 Sukumar Ghosh.
Chapter 6 Advanced Counting 6.1 Recurrence Relations.
A simple example finding the maximum of a set S of n numbers.
CS 2210 (22C:19) Discrete Structures Advanced Counting
April 9, 2015Applied Discrete Mathematics Week 9: Relations 1 Solving Recurrence Relations Another Example: Give an explicit formula for the Fibonacci.
CS2210(22C:19) Discrete Structures Relations Spring 2015 Sukumar Ghosh.
Module #1 - Logic 1 Based on Rosen, Discrete Mathematics & Its Applications. Prepared by (c) , Michael P. Frank and Modified By Mingwu Chen Relations.
Recursion.
1 Section 6.1 Recurrence Relations. 2 Recursive definition of a sequence Specify one or more initial terms Specify rule for obtaining subsequent terms.
Chapter 9 1. Chapter Summary Relations and Their Properties n-ary Relations and Their Applications (not currently included in overheads) Representing.
Applied Discrete Mathematics Week 9: Relations
Advanced Counting Techniques
Chapter 8. Section 8. 1 Section Summary Introduction Modeling with Recurrence Relations Fibonacci Numbers The Tower of Hanoi Counting Problems Algorithms.
Advanced Counting Techniques CSC-2259 Discrete Structures Konstantin Busch - LSU1.
1 Relations and Their Properties Epp, section ??? CS 202 Aaron Bloomfield.
April 10, 2002Applied Discrete Mathematics Week 10: Relations 1 Counting Relations Example: How many different reflexive relations can be defined on a.
13.2 Recursive Definitions Objective 1) Provide the recursive definition for sequences; 2) Identify the type of a sequence from a recursive definition.
Chapter 9. Chapter Summary Relations and Their Properties Representing Relations Equivalence Relations Partial Orderings.
Chapter 9. Chapter Summary Relations and Their Properties n-ary Relations and Their Applications (not currently included in overheads) Representing Relations.
14.1 CompSci 102© Michael Frank Today’s topics Recurrence relationsRecurrence relations –Stating recurrences –LiHoReCoCo –Divide & conquer –Master’s method.
Recurrence Relation. Outline  What is a recurrence relation ?  Solving linear recurrence relations  Divide-and-conquer algorithms and recurrence relations.
CSE 2813 Discrete Structures Recurrence Relations Section 6.1.
Module #20 - Recurrences 1 Ch. 7 Recurrence Relations Rosen 6 th ed., §§7.1.
R. Johnsonbaugh Discrete Mathematics 7 th edition, 2009 Chapter 7 Recurrence Relations Instructor Tianping Shuai.
Module #17: Recurrence Relations Rosen 5 th ed., §
Chapter 9. Section 9.1 Binary Relations Definition: A binary relation R from a set A to a set B is a subset R ⊆ A × B. Example: Let A = { 0, 1,2 } and.
Chapter 7 Advance Counting Techniques. Content Recurrence relations Generating function The principle of inclusion-exclusion.
Chapter 8 With Question/Answer Animations. Chapter Summary Applications of Recurrence Relations Solving Linear Recurrence Relations Homogeneous Recurrence.
Chapter 7: Relations Relations(7.1) Relations(7.1) n-any Relations & their Applications (7.2) n-any Relations & their Applications (7.2)
Advanced Counting Techniques CSC-2259 Discrete Structures Konstantin Busch - LSU1.
Relations and their Properties
1 RELATIONS Learning outcomes Students are able to: a. determine the properties of relations – reflexive, symmetric, transitive, and antisymmetric b. determine.
Relations. Important Definitions We covered all of these definitions on the board on Monday, November 7 th. Definition 1 Definition 2 Definition 3 Definition.
22C:19 Discrete Math Advanced Counting Fall 2010 Sukumar Ghosh.
Relation. Combining Relations Because relations from A to B are subsets of A x B, two relations from A to B can be combined in any way two sets can be.
Problem Statement How do we represent relationship between two related elements ?
Chapter 9. Chapter Summary Relations and Their Properties n-ary Relations and Their Applications (not currently included in overheads) Representing Relations.
Unit II Discrete Structures Relations and Functions SE (Comp.Engg.)
Agenda Lecture Content:  Recurrence Relations  Solving Recurrence Relations  Iteration  Linear homogenous recurrence relation of order k with constant.
1 RELATIONS Learning outcomes Students are able to: a. determine the properties of relations – reflexive, symmetric, transitive, and antisymmetric b. determine.
Chapter 8: Relations. 8.1 Relations and Their Properties Binary relations: Let A and B be any two sets. A binary relation R from A to B, written R : A.
CMSC Discrete Structures
Learn about relations and their basic properties
Relations Chapter 9.
Modeling with Recurrence Relations
Applied Discrete Mathematics Week 11: Relations
Introduction to Recurrence Relations
Taibah University College of Computer Science & Engineering Course Title: Discrete Mathematics Code: CS 103 Chapter 9 Relations Slides are adopted from.
Module #17: Recurrence Relations
Discrete Structures for Computer Science
CS2210 Discrete Structures Relations
Module #17: Recurrence Relations
CS 2210 Discrete Structures Advanced Counting
CMSC Discrete Structures
CSE 321 Discrete Structures
Applied Discrete Mathematics Week 7: Computation
CMSC Discrete Structures
Recurrence Relations Discrete Structures.
ICS 253: Discrete Structures I
Presentation transcript:

22C:19 Discrete Structures Advanced Counting Spring 2014 Sukumar Ghosh

Compound Interest A person deposits $10,000 in a savings account that yields 10% interest annually. How much will be there in the account After 30 years? Let P n = account balance after n years. Then P n = P n P n-1 = 1.1P n-1 Note that the definition is recursive. What is the solution P n ?

Recurrence Relation Recursively defined sequences are also known as recurrence relations. The actual sequence is a solution of the recurrence relations. Consider the recurrence relation: a n+1 = 2a n (n > 0) [Given a 1 =1] The solution is: 1, 2, 4, 8, 16 …., i.e. a n = 2 n-1 So, a 30 = 2 29 Given any recurrence relation, can we solve it?

Example of Recurrence Relations 1.Fibonacci sequence: a n = a n-1 + a n-2 (n>2) [Given a 1 = 1, a 2 = 1] What is the formula for a n ? 2.Find the number of bit strings of length n that do not have two consecutive 0s. For n=1, the strings are 0 and 1 For n=2, the strings are 01, 10, 11 For n=3, the strings are 011, 111, 101, 010, 110 Do you see a pattern here?

Example of Recurrence Relations Let a n be the number of bit strings of length n that do not have two consecutive 0s. a n = a n-1 + a n-2 (why?) [bit string of length (n-1) without a 00 anywhere] 1(a n-1 ) and [bit string of length (n-2) without a 00 anywhere] 1 0(a n-2 ) a n = a n-1 + a n-2 is a recurrence relation. Given this, can you find a n ?

Tower of Hanoi Transfer these disks from one peg to another. However, at no time, a disk should be placed on another disk of smaller size. Start with 64 disks. When you have finished transferring them one peg to another, the world will end.

Tower of Hanoi Let, H n = number of moves to transfer n disks. Then H n = 2H n-1 +1 Can you solve this and compute H 64 ? (H 1 = 1. why?)

Solving Linear Recurrence Relations A linear recurrence relation is of the form a n = c 1.a n-1 + c 2. a n-2 + c 3. a n-3 + …+ c k. a n-k (here c 1, c 2, …, c n are constants) Its solution is of the form a n = r n (where r is a constant) if and only if r is a solution of r n = c 1.r n-1 + c 2. r n-2 + c 3. r n-3 + …+ c k. r n-k This equation is known as the characteristic equation.

Example 1 Solve: a n = a n a n-2 (Given that a 0 = 2 and a 1 = 7) Its solution is of the forma n = r n The characteristic equation is: r 2 = r + 2, i.e. r 2 - r - 2 = 0. It has two roots r = 2, and r = -1 The sequence {a n } is a solution to this recurrence relation iff a n = α 1 2 n + α 2 (-1) n a 0 = 2 = α 1 + α 2 a 1 = 7 = α α 2.(-1)This leads to α 1 = 3 + α 2 = -1 So, the solution is a n = 3. 2 n - (-1) n

Example 2: Fibonacci sequence Solve: f n = f n-1 + f n-2 (Given that f 0 = 0 and f 1 = 1) Its solution is of the formf n = r n The characteristic equation is:r 2 - r - 1 = 0. It has two roots r = ½(1 + 5 ) and ½(1 - 5 ) The sequence {a n } is a solution to this recurrence relation iff f n = α 1 (½(1 + 5 )) n + α 2 (½(1 - 5 )) n (Now, compute α 1 and α 2 from the initial conditions): α 1 = 1/ 5 and α 2 = -1/ 5 The final solution is f n = 1/ 5. (½(1 + 5 )) n - 1/ 5.(½(1 - 5 )) n

Divide and Conquer Recurrence Relations Some recursive algorithms divide a problem of size n into b sub-problems each of size n/b, and derive the solution by combining the results from these sub-problems. This is known as the divide-and-conquer approach Example 1. Binary Search: If f(n) comparisons are needed to search an object from a list of size n, then f(n) = f(n/2) + 2

Divide and Conquer Recurrence Relations Example 2: Finding the maximum and minimum of a sequence f(n) = 2.f(n/2) + 2 Example 3. Merge Sort: Divide the list into two sublists, sort each of them and then merge. Here f(n) = 2.f(n/2) + n

Divide and Conquer Recurrence Relations The solution to a recurrence relations of the form f(n) = a.f(n/b) + c (here b divides n, a1, b>1, and c is a positive real number) is f(n) (if a=1) (if a>1) (I encourage to to see the derivation in page 530)

Divide and Conquer Recurrence Relations Apply to binary search f(n) = f(n/2) + 2 The complexity of binary searchf(n) (since a=1) What about finding the maximum or minimum of a sequence? f(n) = 2f(n/2) + 2 So, the complexity is f(n)

22C:19 Discrete Structures Relations Spring 2014 Sukumar Ghosh

What is a relation?

Representing Relations

Relations vs. Functions

When to use which? A function yields a single result for any element in its domain. Example: age (of a person), square (of an integer) etc. A relation allows multiple mappings between the domain and the co-domain. Example: students enrolled in multiple courses.

Relation within a set

Properties of Relations We study six properties of relations: What are these?

Reflexivity Example. = is reflexive, since a = a is reflexive, since a a < is not reflexive is a < a is false.

Symmetry

Anti-symmetry

More on symmetric relations

Transitivity

Examples of transitive relations

Summary of properties =<> ReflexiveXXX IrreflexiveXX SymmetricX AsymmetricXXXX AntisymmetricXXX TransitiveXXXXX

Operations on relations Then, R1 R2 = {(1,1), (1,2), (1,3), (1,4)} R1 R2 = {(1,1), (1,3)} R1 - R2 = {(1,2)} Let A = {1, 2, 3} and B = (1, 2, 3, 4}. Define two relations R1 = {(1,1), (1,2), (1,3)} R2 = {(1,1), (1,3), (1,4)}

More operations on relations: Composition Let S be a relation from the set A to the set B, and R be and R be a relation from the set B to the set C. Then, the composition of S and R, denoted by S R is { (a, c) | a A, b B, c C such that (a, b) S and (b, c) R} EXAMPLE. Let A = {1, 2, 3}, B = { 1, 2, 3, 4}, C = {0, 1, 2} S = {(1,1), (1,4), (2,3), (3, 1), (3, 4)} R = {(1,0), (2,0), (3,1), (3, 2), (4,1) Then S R = {(1,0), (1,1), (2,1), (2,2), (3,0), (3,1)

More operations on relations: Composition R n = R n-1 R = R R R R … (n times) EXAMPLE. Let R = {(1,1), (2,1), (3,2), (4,3)},. Then R 2 = R R = {(1,1), (2,1), (3, 1), (4,2)} R 3 = R 2 R = {(1,1), (2,1), (3, 1), (4,1)} R 4 = R 3 R = {(1,1), (2,1), (3, 1), (4,1)} Notice that in this case for all n > 3, R n = R 3

n-ary relations Has important applications in computer databases. DEFINITION. Let A 1, A 2, A 3, …, A n be n sets. An n-ary relation is a subset of A 1 x A 2 x A 3 x… x A n EXAMPLE. R is a relation on N x N x N consisting of triples (a, b, c) where a < b < c. Thus (1, 2, 3) R but (3, 6, 2) R b

Relational Data Model NameIDMajorGPA Alice Physics3.67 Bob ECE3.67 Carol ECE3.75 David Computer Science3.25 The above table can be viewed as a 4-ary relation consisting of the 4-tuples (Alice, , Physics, 3.67) (Bob, , ECE, 3.67) (Carol, , ECE, 3.75) (David, , Computer Science, 3.25) Student Record

Relational Data Model NameIDMajorGPA Alice Physics3.67 Bob ECE3.67 Carol ECE3.75 David Computer Science3.25 A domain is called a primary key when no two n-tuples in the relation have the same value from this domain. (These are marked red).

Operations on n-ary relations SELECTION Let R be an n-ary relation, and C be a condition that the elements in R must satisfy. Then the selection operator S C maps the n-ary relation R to the n-ary relations from R that satisfy the condition C. Essentially it helps filter out tuples that satisfy the desired properties. For example, you may filter out the tuples for all students in ECE, or all students whose GPA exceeds 3.5.

Operations on n-ary relations PROJECTION The projection P i,j,k,…,m maps each n-tuple (a 1, a 2, a 3, …, a n ) to the tuple (a i, a j, a k, …, a m ). Essentially it helps you delete some of the components of each n-tuple. Thus, in the table shown earlier, the projection P 1,4 will retain only that part of the table that contains the student names and their GPAs.

Use of the operations on n-ary relations SQL queries SQL queries carry out the operations described earlier: SELECT GPA FROM Student Records WHERE Department = Computer Science

Representing Relations Using Matrices A relation between finite sets can be represented using a 0-1 matrix. Let A = {a 1, a 2, a 3 } and B = {b 1, b 2, b 3 }. A relation R from A to B can be represented by a matrix M R, where m ij = 1 if (a i, b j ) R, otherwise m ij = 0 a1 a2 a3 b1b2b3 The above denotes a relation R from A = {1,2,3} to B = {1,2,4}, where for each element (a, b) of R, a > b

Representing Relations Using Matrices A reflexive relation on a given set A is recognized by a 1 along the diagonal A symmetric relation A reflexive relation

Representing Relations Using Digraph A relation on a given set A can also be represented by a directed graph A directed graph representation of the relation shown on the left Let A = {1, 2, 3}

Equivalence Relations An equivalence relation on a set S is a relation that is reflexive, symmetric and transitive. Examples are: (1)Congruence relation R = {(a,b) | a = b (mod m)} (2) R = {(a, b) | L(a) = L(b)} in a set of strings of English characters}, L(a) denotes the length of English character string a

Partial Orders A relation R on a set S is a partial order if it is reflexive, anti-symmetric and transitive. The set is called a partially ordered set, or a poset. Examples are (1) the relation, (2) x divides y on the set of positive integers (3) The relation on the power set of a set S

Partial Orders Source: The relation on the power set of a set S forms a partially ordered set