Discrete Structures May 13, (40 points) Define each of the following terms:

Similar documents
Discrete Structures: Sample Questions, Exam 2, SOLUTIONS

Economics 204 Summer/Fall 2017 Lecture 1 Monday July 17, 2017

MATH 433 Applied Algebra Lecture 14: Functions. Relations.

Department of Computer Science University at Albany, State University of New York Solutions to Sample Discrete Mathematics Examination II (Fall 2007)

Problem 1: Suppose A, B, C and D are finite sets such that A B = C D and C = D. Prove or disprove: A = B.

Discrete Mathematics Fall 2018 Midterm Exam Prof. Callahan. Section: NetID: Multiple Choice Question (30 questions in total, 4 points each)

Department of Computer Science University at Albany, State University of New York Solutions to Sample Discrete Mathematics Examination I (Spring 2008)

Relations MATH Relations. Benjamin V.C. Collins, James A. Swenson MATH 2730

NOTE: You have 2 hours, please plan your time. Problems are not ordered by difficulty.

Discrete Structures: Sample Questions, Exam 2, SOLUTIONS

Practice Midterm Exam

3. R = = on Z. R, S, A, T.

Math 230 Final Exam, Spring 2008

Searching Algorithms. CSE21 Winter 2017, Day 3 (B00), Day 2 (A00) January 13, 2017

Chapter 3. Cartesian Products and Relations. 3.1 Cartesian Products

Foundations of algebra

Exam Practice Problems

Relations and Equivalence Relations

Relations. We have seen several types of abstract, mathematical objects, including propositions, predicates, sets, and ordered pairs and tuples.

Section 7.1 Relations and Their Properties. Definition: A binary relation R from a set A to a set B is a subset R A B.

CHAPTER 1. Relations. 1. Relations and Their Properties. Discussion

Sets. A set is a collection of objects without repeats. The size or cardinality of a set S is denoted S and is the number of elements in the set.

HL Test 2018 Sets, Relations and Groups [50 marks]

Generating Permutations and Combinations

Algorithms 2/6/2018. Algorithms. Enough Mathematical Appetizers! Algorithm Examples. Algorithms. Algorithm Examples. Algorithm Examples

Discrete Structures CRN Test 3 Version 1 CMSC 2123 Spring 2011

Recurrences COMP 215

Week 4-5: Binary Relations

Real Analysis. Joe Patten August 12, 2018

Time Analysis of Sorting and Searching Algorithms

9 RELATIONS. 9.1 Reflexive, symmetric and transitive relations. MATH Foundations of Pure Mathematics

CIS 375 Intro to Discrete Mathematics Exam 3 (Section M004: Blue) 6 December Points Possible

Relations (3A) Young Won Lim 3/27/18

(c) Give a proof of or a counterexample to the following statement: (3n 2)= n(3n 1) 2

Practice Exam 1 CIS/CSE 607, Spring 2009

REVIEW QUESTIONS. Chapter 1: Foundations: Sets, Logic, and Algorithms

Chapter 1. Sets and Numbers

Week 4-5: Binary Relations

COMP 182 Algorithmic Thinking. Relations. Luay Nakhleh Computer Science Rice University

CIS 375 Intro to Discrete Mathematics Exam 3 (Section M001: Green) 6 December Points Possible

Chapter 8 Dynamic Programming

(1) Which of the following are propositions? If it is a proposition, determine its truth value: A propositional function, but not a proposition.

Math 210 Exam 2 - Practice Problems. 1. For each of the following, determine whether the statement is True or False.

Week 4-5: Generating Permutations and Combinations

This means that we can assume each list ) is

Packet #5: Binary Relations. Applied Discrete Mathematics

Lecture 1. Econ 2001: Introduction to Mathematical Methods (a.k.a. Math Camp) 2015 August 10

Introduction. Foundations of Computing Science. Pallab Dasgupta Professor, Dept. of Computer Sc & Engg INDIAN INSTITUTE OF TECHNOLOGY KHARAGPUR

Chapter 8 Dynamic Programming

Topic 17. Analysis of Algorithms

MATH 3300 Test 1. Name: Student Id:

Mathematical Structures Combinations and Permutations

CS2223 Algorithms D Term 2009 Exam 3 Solutions

Foundations of Mathematics MATH 220 FALL 2017 Lecture Notes

Relations. Relations of Sets N-ary Relations Relational Databases Binary Relation Properties Equivalence Relations. Reading (Epp s textbook)

XMA2C011, Annual Examination 2012: Worked Solutions

The Complexity of Optimization Problems

Is g one-to-one? Is g onto? Why? Solution: g is not one-to-one, since for c A, g(b) = g(c) = c. g is not onto, since a / g(a).

Midterm Exam. CS 3110: Design and Analysis of Algorithms. June 20, Group 1 Group 2 Group 3

Reading 11 : Relations and Functions

CSE 20 DISCRETE MATH. Winter

Math 3000 Section 003 Intro to Abstract Math Final Exam

CS 4407 Algorithms Lecture 2: Iterative and Divide and Conquer Algorithms

Committee Selection with a Weight Constraint Based on Lexicographic Rankings of Individuals

Math 230 Final Exam, Spring 2009

Math Introduction to Logic Final Exam

Discrete Structures: Solutions to Sample Questions, Exam 2

At least one of us is a knave. What are A and B?

CPSC 320 (Intermediate Algorithm Design and Analysis). Summer Instructor: Dr. Lior Malka Final Examination, July 24th, 2009

Outline. 1 Introduction. Merging and MergeSort. 3 Analysis. 4 Reference

CIS 375 Intro to Discrete Mathematics Exam 2 (Section M001: Yellow) 10 November Points Possible

Selected Solutions to Even Problems, Part 3

Exam 2. Is g one-to-one? Is g onto? Why? Solution: g is not one-to-one, since for c A, g(b) = g(c) = c. g is not onto, since a / g(a).

Mathematical Induction

CS Analysis of Recursive Algorithms and Brute Force

Exam in Discrete Mathematics

CPS 616 DIVIDE-AND-CONQUER 6-1

The Meet-Over-All-Paths Solution to Data-Flow Problems

Final Exam Review. 2. Let A = {, { }}. What is the cardinality of A? Is

Lecture 7: Relations

Analysis of Algorithm Efficiency. Dr. Yingwu Zhu

MATH 363: Discrete Mathematics

Growth of Functions. As an example for an estimate of computation time, let us consider the sequential search algorithm.

CA320 - Computability & Complexity

Algorithm. Executing the Max algorithm. Algorithm and Growth of Functions Benchaporn Jantarakongkul. (algorithm) ก ก. : ก {a i }=a 1,,a n a i N,

CSC2100B Data Structures Analysis

Outline. 1 Introduction. 3 Quicksort. 4 Analysis. 5 References. Idea. 1 Choose an element x and reorder the array as follows:

Practice Final Solutions. 1. Consider the following algorithm. Assume that n 1. line code 1 alg(n) { 2 j = 0 3 if (n = 0) { 4 return j

MATH 215 Sets (S) Definition 1 A set is a collection of objects. The objects in a set X are called elements of X.

CSE548, AMS542: Analysis of Algorithms, Spring 2014 Date: May 12. Final In-Class Exam. ( 2:35 PM 3:50 PM : 75 Minutes )

Order Relations and Functions

Discrete Mathematics CS October 17, 2006

Proofs. Joe Patten August 10, 2018

Fall 2016 Test 1 with Solutions

Module 1: Analyzing the Efficiency of Algorithms

Exam in Discrete Mathematics

Propositional Logic. What is discrete math? Tautology, equivalence, and inference. Applications

Discrete Mathematics with Applications MATH236

UNIVERSITY OF VICTORIA DECEMBER EXAMINATIONS MATH 122: Logic and Foundations

Math 283 Spring 2013 Presentation Problems 4 Solutions

Transcription:

Discrete Structures May 13, 2014 Prof Feighn Final Exam 1. (40 points) Define each of the following terms: (a) (binary) relation: A binary relation from a set X to a set Y is a subset of X Y. (b) function: A function from a set X to a set Y is a relation from X to Y such that each x X is related to exactly one y Y. (c) onto: A function f : X Y is onto if, for every y Y, there is x X such that f(x) = y. (d) one-to-one: A function f : X Y is one-to-one if, for all x, x X, we have that f(x) = f(x ) implies x = x. (e) transitive: A relation R on a set X is transitive if we have that xry and yrz implies xrz. (f) equivalence relation: A relation on a set X is an equivalence relation if it is reflexive, symmetric, and transitive. (g) equivalence class: A subset A of X is an equivalence class of an equivalence relation R on X if there is x X such that A = {y X yrx}. (h) recurrence relation: A recurrence relation for the sequence a 1, a 2,... is an expression for a n in terms of its predecessors.

2. (10 points) Construct the truth table for (p = q) ( q = p) p q p = q q p q p (p = q) ( q = p) T T T F F T T T F F T F F T F T T F T T T F F T T T T T 3. (10 points) For integers x, y Z write x y if y x is a multiple of three. Show that is an equivalence relation on Z. (Recall that Z = {..., 2, 1, 0, 1, 2,... } and that n Z is a multiple of three if and only if n = 3m for some m Z.) Proof. is reflexive: Let x Z. Then x x = 3 0 and so x x. is symmetric: Asssume x, y Z and x y. Then there is m Z so that y x = 3m. Then x y = 3( m) and so y z. is transitive: Assume x, y, z Z, y y and y z. Then there is m, n Z so that y x = 3m and z y = 3n. Hence z x = 3(m + n) and so x z. 4. (10 points) Prove that, for all sets X, Y, and Z, X (Y Z) (X Y ) (X Z) Proof. Let t X (Y Z). Then t X and t (Y Z). Therefore t X and t Y or t X and t Z. In the first case t X Y and in the second case t X Z. In any case, t (X Y ) (X Z). 5. (10 points) Prove by induction that for all positive integers n. 2 + 4 + 6 + + 2n = n(n + 1)

Proof. Let P (n) be the proposition that 2 + 4 + 6 + + 2n = n(n + 1) We will prove by induction that P (n) holds for all positive integers n. Base case (P (1) is true): Suppose n = 1. We have 2 = 1(1 + 1) and P (1) is true. Inductive case (P (n) = P (n + 1) is true): Suppose P (n) is true for the positive integer n. Then 2 + 4 + 6 + + 2n + 2(n + 1) =n(n + 1) + 2(n + 1) and so P (n + 1) is true. =(n + 1)(n + 2) 6. (10 points) Consider f : N N given by f(n) = n 3. (a) Is f 1-1? If so, prove it. Otherwise find a counterexample. f is 1-1. Proof. Let x, x N. Suppose f(x 1 ) = f(x 2 ). Then x 3 1 = x 3 2. It follows that x 3 1 x 3 2 = (x 1 x 2 )(x 2 1 x 1 x 2 + x 2 2) = 0. Since x 2 1 x 1 x 2 +x 2 2 = (x 1 x 2 ) 2 +x 1 x 2 is the sum of a non-negative term and a positive term, this second term is never zero. So x 3 1 x 3 2 = 0 implies that x 1 = x 2. (b) Is f onto? If so, prove it. Otherwise find a counterexample. The function f is not onto. For example, 2 is not the cube of a natural number. 7. (20 points) For A = {a, b}, B = {b, c} and U = {a, b, c, d}, compute each of the following. (a) A B = {b} (b) A B = {a} (c) A A = {(a, a), (a, b), (b, a), (b, b)} (d) B = {a, b}

8. Let R be the relation given by the digraph below. 1 2 3 (a) (5 points) Write the matrix M for R. 1 1 0 M = 1 1 0 0 0 1 (b) (5 points) Compute M 2. M 2 = 2 2 0 2 2 0 0 0 1 (c) (10 points) Prove that R is an equivalence relation. Proof. R is reflexive since all diagonal entries of M are non-zero. R is symmetric since M is symmetric. R is transitive because if an entry of M 2 is non-zero then the corresponding entry of M is also non-zero. 9. (10 points) In each of the following two problems, compute t(n) where t(n) is the number of times the statement x = x + 1 is executed. Be sure to explain your answers. (a) for i = 1 to n for j = 1 to i x = x + 1 t(n) = 1 + 2 + 3 + + n = n(n + 1) n

(b) i = 2 n while (i 1){ x = x + 1 i = i/2 } The while loop is executed log 2 (2 n ) + 1 = n + 1 times and each of these times x = x + 1 is executed once. Therefore t(n) = n + 1 10. (10 points) Consider the relational databases given by the three tables below. Write a sequence of operations to answer the following query. Find all buyers who buy parts from Jones s department together with the numbers of those parts. Temp1:=DEPARTMENT[Manager=Jones] Temp2:=Temp1[Dept=Dept]SUPPLIER Temp3:=Temp2[Part No=Part No]BUYER Answer:=Temp3[Name, Part No]. Table 1: DEPARTMENT Dept Manager 23 Jones 04 Yu 96 Zamora 66 Washington Table 2: BUYER Name Part No United Supplies 2A ABC Unlimited 8C200 United Supplies 1199C JCN Electronics 2A United Supplies 335B2 ABC Unlimited 772 Danny s 900 United Supplies 772 Underhanded Sales 20A8 Danny s 20A8 DePaul University 42C ABC Unlimited 20A8

Table 3: SUPPLIER Dept Part No Amount 04 335B2 220 23 2A 14 04 8C200 302 66 42C 3 04 900 7720 96 20A8 200 96 1199C 296 23 772 39 23 99999999 0 11. (15 points) Solve the following recurrence relations. (a) a n = 5 + a n 1 with initial condition a 0 = 3. a n = 5 + a n 1 = 5 + (5 + a n 1 ) = 2 5 + a n 2 = = k 5 + a n k Setting k = n, we have a n = n 5 + a 0 = 5n + 3. (b) a n = 3a n 1 2a n 2 with initial conditions a 0 = 8, a 1 = 13. The equation x 2 3x + 2 has roots x = 1 and x = 2. Hence a n = b 1 n + d 2 n. The initial conditions give 8 =b + d 13 =b + 2d which has solution b = 3 and d = 5. We conclude a n = 3 + 5 2 n. (c) a n = 6a n 1 9a n 2 with initial conditions a 0 = 1, a 1 = 12. The equation x 2 6x + 9 has the double root x = 3. Hence a n = b3 n + dn3 n. The initial conditions give 1 =b 12 =3b + 3d which has solution b = 1 and d = 3. We conclude a n = 3 n +3n3 n = 3 n (1 + 3n).

12. (20 points) Here is pseudocode for our binary search algorithm. Input: A sequence s i, s i+1,..., s j, i 1 sorted in nodecreasing order, a value key, i, and j. Output: The output is an index k for which s k = key or if key is not in the sequence, the output is the value 0. 1. binary search(s, i, j, key){ 2. if (i > j) //not found 3. return 0 4. k = (i + j)/2 5. if (key == s k ) //found 6. return k 7. if (key < s k ) // search left half 8. j = k 1 9. else // search right half 10. i = k + 1 11. return binary search(s, i, j, key) 12. } (a) Show how this algorithm works for the input s 1 = B, s 2 = D, s 3 = F, s 4 = S and key = S. At the start i = 1 and j = 4. Since 1 4, k = 2. Now key D and key D and so i = 3. We now execute binary search to the data s 3 = F and s 4 = S with the same key. Since 3 4, k = 3. Now key F and key S and so i = 4. We next execute binary search to the data s 4 = S. Since 4 4, k = 4. This time key = S is true and so k = 4 is returned. (b) Let b n be the number of times the algorithm is called in the worst case where the input sequence has n items. Explain why b 1 = 2 and b n = 1 + b n/2

For n 0, binary search is called once at the beginning. In the worst case, key is not present. If n = 1, binary search is called again at line 11, but this time with i > j and so binary search is not called again. We conclude that b 1 = 2. If n > 1, then binary search is called again at line 11, but with j i = n/2. Hence b n = 1 + b n/2. (c) Find b 2, b 3, and b 4. b 2 = 3, b 3 = 3, b 4 = 4 (d) Solve the recurrence relation in part b) for b n in case n is a power of 2, i.e. n = 2 k. We have b 2 k = 1 + b 2 k 1 = 1 + (1 + b 2 k 2) = 2 + b 2 k 2 = = m + b 2 k m Setting m = k, we obtain b 2 k = k + b 2 0 = k + 2 = log 2 (n) + 2.