Discrete Mathematics for CS Spring 2005 Clancy/Wagner MT 1

Similar documents
Full and Complete Binary Trees

Mathematical Induction. Lecture 10-11

Mathematical Induction

Handout #1: Mathematical Reasoning

6.3 Conditional Probability and Independence

Binary Search Trees CMPSC 122

Chapter 3. Cartesian Products and Relations. 3.1 Cartesian Products

Introduction to Algorithms March 10, 2004 Massachusetts Institute of Technology Professors Erik Demaine and Shafi Goldwasser Quiz 1.

Section IV.1: Recursive Algorithms and Recursion Trees

CS473 - Algorithms I

Data Structures Fibonacci Heaps, Amortized Analysis

Binary Search Trees. Data in each node. Larger than the data in its left child Smaller than the data in its right child

CS 103X: Discrete Structures Homework Assignment 3 Solutions

Introduction. Appendix D Mathematical Induction D1

CS 3719 (Theory of Computation and Algorithms) Lecture 4

Sorting revisited. Build the binary search tree: O(n^2) Traverse the binary tree: O(n) Total: O(n^2) + O(n) = O(n^2)

3. Mathematical Induction

Binary Heap Algorithms

Basic Proof Techniques

Recursive Algorithms. Recursion. Motivating Example Factorial Recall the factorial function. { 1 if n = 1 n! = n (n 1)! if n > 1

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

Lecture 16 : Relations and Functions DRAFT

Lecture 1: Course overview, circuits, and formulas

Analysis of Algorithms I: Optimal Binary Search Trees

MATH 289 PROBLEM SET 4: NUMBER THEORY

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

GRAPH THEORY LECTURE 4: TREES

Automata and Formal Languages

Lecture 17 : Equivalence and Order Relations DRAFT

Binary Heaps * * * * * * * / / \ / \ / \ / \ / \ * * * * * * * * * * * / / \ / \ / / \ / \ * * * * * * * * * *

From Last Time: Remove (Delete) Operation

CSE373: Data Structures and Algorithms Lecture 3: Math Review; Algorithm Analysis. Linda Shapiro Winter 2015

Digital System Design Prof. D Roychoudhry Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur

Math 55: Discrete Mathematics

The Prime Numbers. Definition. A prime number is a positive integer with exactly two positive divisors.

Basics of Counting. The product rule. Product rule example. 22C:19, Chapter 6 Hantao Zhang. Sample question. Total is 18 * 325 = 5850

Solutions for Practice problems on proofs

Mathematical Induction

8 Divisibility and prime numbers

Outline BST Operations Worst case Average case Balancing AVL Red-black B-trees. Binary Search Trees. Lecturer: Georgy Gimel farb

If n is odd, then 3n + 7 is even.

Graph Theory Problems and Solutions

The last three chapters introduced three major proof techniques: direct,

MAT Program Verication: Exercises

CS510 Software Engineering

s = s = s =

Dynamic Programming Problem Set Partial Solution CMPSC 465

Heaps & Priority Queues in the C++ STL 2-3 Trees

Research Tools & Techniques

Reading 13 : Finite State Automata and Regular Expressions

Lecture 13 - Basic Number Theory.

Sample Induction Proofs

Continued Fractions and the Euclidean Algorithm

Near Optimal Solutions

CS711008Z Algorithm Design and Analysis

Cartesian Products and Relations

Math 319 Problem Set #3 Solution 21 February 2002

Cosmological Arguments for the Existence of God S. Clarke

A Non-Linear Schema Theorem for Genetic Algorithms

mod 10 = mod 10 = 49 mod 10 = 9.

Properties of Real Numbers

Regular Languages and Finite Automata

Binary Adders: Half Adders and Full Adders

Correspondence analysis for strong three-valued logic

CONTINUED FRACTIONS AND PELL S EQUATION. Contents 1. Continued Fractions 1 2. Solution to Pell s Equation 9 References 12

6.2 Permutations continued

DIFFERENTIABILITY OF COMPLEX FUNCTIONS. Contents

International Journal of Advanced Research in Computer Science and Software Engineering

Lectures notes on orthogonal matrices (with exercises) Linear Algebra II - Spring 2004 by D. Klain

CHAPTER 3. Methods of Proofs. 1. Logical Arguments and Formal Proofs

Dimitris Chatzidimitriou. Corelab NTUA. June 28, 2013

WRITING PROOFS. Christopher Heil Georgia Institute of Technology

COMPSCI 105 S2 C - Assignment 2 Due date: Friday, 23 rd October 7pm

INCIDENCE-BETWEENNESS GEOMETRY

Lecture 5 - CPA security, Pseudorandom functions

A binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and:

V. Adamchik 1. Graph Theory. Victor Adamchik. Fall of 2005

Binary Heaps. CSE 373 Data Structures

Logic in Computer Science: Logic Gates

MATH 22. THE FUNDAMENTAL THEOREM of ARITHMETIC. Lecture R: 10/30/2003

Ummmm! Definitely interested. She took the pen and pad out of my hand and constructed a third one for herself:

Real Roots of Univariate Polynomials with Real Coefficients

CS 598CSC: Combinatorial Optimization Lecture date: 2/4/2010

CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) Total 92.

Notes on Complexity Theory Last updated: August, Lecture 1

MATH10040 Chapter 2: Prime and relatively prime numbers

3515ICT Theory of Computation Turing Machines

Analysis of Algorithms I: Binary Search Trees

Algorithms and Data Structures

CoNP and Function Problems

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team

Introduction to Automata Theory. Reading: Chapter 1

Classification/Decision Trees (II)

The Union-Find Problem Kruskal s algorithm for finding an MST presented us with a problem in data-structure design. As we looked at each edge,

CONTENTS 1. Peter Kahn. Spring 2007

CSE 135: Introduction to Theory of Computation Decidability and Recognizability

Row Echelon Form and Reduced Row Echelon Form

Data Structures and Algorithms Written Examination

n k=1 k=0 1/k! = e. Example 6.4. The series 1/k 2 converges in R. Indeed, if s n = n then k=1 1/k, then s 2n s n = 1 n

Sequential Data Structures

Transcription:

CS 70 Discrete Mathematics for CS Spring 2005 Clancy/Wagner MT 1 PRINT your name:, (last) SIGN your name: (first) PRINT your class account name: cs70- Name of the person sitting to your left: Name of the person sitting to your right: You may consult any books, notes, or other paper-based inanimate objects available to you. Calculators and computers are not permitted. Please write your answers in the spaces provided in the test; in particular, we will not grade anything on the back of an exam page unless we are clearly told on the front of the page to look there. You have 80 minutes. There are 5 questions, of varying credit (40 points total). The questions are of varying difficulty, so avoid spending too long on any one question. Do not turn this page until your instructor tells you to do so. Problem 1 Problem 2 Problem 3 Problem 4 Problem 5 Total CS 70, Spring 2005, MT 1 1

Problem 1. [True or false] (12 points) Circle TRUE or FALSE. You do not need to justify your answers on this problem. Reminder: N = {0, 1, 2, 3,...} represents the set of non-negative integers. (a) TRUE or FALSE: The propositions P = Q and Q = P are logically equivalent. (b) TRUE or FALSE: The proposition Q P (P = Q) is guaranteed to be true, no matter what the truth values of P and Q may be. (c) TRUE or FALSE: If we are told that the proposition P is true, we are entitled to conclude that ((P = Q) = P) = Q must also be true. (d) TRUE or FALSE: n N. (x 2 x = 0) (x 2). (e) TRUE or FALSE: x N. y N. z N. x + y = z. (f) TRUE or FALSE: x N. y N. x 2 = y. (g) TRUE or FALSE: ( x N. y N. x < y) ( y N. x N. x < y). (h) TRUE or FALSE: Let P(n) denote the proposition that 1 + 2 + + n + (n + 1) = n(n + 1)/2. Then n N. P(n) = P(n + 1) is true. (i) TRUE or FALSE: Define the relation so that n m iff n divides m and n < m. Then the relation is a well-ordering on N. (j) TRUE or FALSE: Any 2-party cake-cutting protocol that is fair is also envy-free. (k) TRUE or FALSE: In the stable marriage problem, if M denotes the male-optimal matching, then there exists a girl who does not get her optimal boy in M (i.e., her mate in M is not her optimal boy). (l) TRUE or FALSE: Suppose that we have n boys, b 1,...,b n, and n girls, g 1,...,g n. Assume that g 1 lists b 1 as her top choice, g 2 lists b 2 as her top choice, and so on, so that b i appears at the front of g i s preference list for all i. If we run the Traditional Marriage Algorithm, then the resulting matching is guaranteed to match g i to b i for all i. CS 70, Spring 2005, MT 1 2

Problem 2. [A peculiar sequence] (6 points) Define u 0 = u 1 = 1, and define u n = (n 1)u n 2 for n = 2,3,4,... By convention, 0! = 1. Prove that u n+1 u n = n! for all n N. CS 70, Spring 2005, MT 1 3

Problem 3. [Recognizing complete binary trees] (6 points) A binary tree is a tree with the property that every internal node (i.e., every non-leaf node) has exactly two children. A binary tree is called complete if all its leaves are at the same depth. Assume that if T is a tree, then the helper function (leaf? T) returns true iff T has no children. Also, if T is a tree with children, then (left T) returns the left subtree of T and (right T) returns the right subtree of T. Consider the following algorithm: (define (complete? T) (if (leaf? T) #t (and (complete? (left T)) (complete? (right T))) ) ) Here is an attempt to prove this algorithm correct. Theorem 0.1: For all trees T, if (complete? T) returns true, then there exists k N such that every leaf is at distance k from the root of T. Proof: Use proof by structural induction. Base case: Suppose the tree T has no children, so that (leaf? T) returns true. Then (complete? T) also returns true, and moreover every leaf is at distance 0 from the root (i.e., k = 0), so the implication is true in this case. Inductive step: Assume the claim is true for trees TL and TR. Suppose the tree T is constructed so that the left subtree of the root is TL, and the right subtree is TR. Assume (complete? T) returns true. By the definition of (complete? T), this means that (complete? TL) and (complete? TR) must both have returned true. Then, by the induction hypothesis, there is some k so that every leaf of TL is at distance k from the root of TL. Similarly, there is some k so that every leaf of TR is at distance k from the root of TR. In both cases, the leaf is at distance k + 1 from the root of T (by the way that T was constructed from TL and TR). Also, every leaf of T falls into one of these two cases. Consequently, we have proven that if (complete? T) returns true, then there exists k N so that every leaf of T is at distance k from the root of T (in fact, k = k + 1). This problem is continued on the following page. CS 70, Spring 2005, MT 1 4

Please tell us whether this proof is valid. In particular, answer each of the following questions with Yes or No, and explain your answer: (a) Is the use of structural induction appropriate? (b) Is the proof of the base case OK? (c) Is the proof of the inductive step OK? (d) Bottom line: Is the proof valid? CS 70, Spring 2005, MT 1 5

Problem 4. [Working with expressions some more] (8 points) This question involves expressions generated by the following rules. (Note that rule 2. is slightly different from what you saw on a previous quiz.) 1. A single digit is an expression. 2. If E 1 and E 2 are expressions, then E 1 E 2 is an expression. 3. If E is an expression, then (E) is an expression. Prove that no expression generated by the three rules above contains an open parenthesis immediately followed by a close parenthesis, i.e. (). CS 70, Spring 2005, MT 1 6

Problem 5. [A variant on merge sort] (8 points) Let F k denote the kth Fibonacci number. Reminder: the Fibonacci numbers are defined by F 0 = F 1 = 1, and F k = F k 1 + F k 2 for k 2. Consider the following variation on merge sort, which assumes that the number of elements in its list argument L is a Fibonacci number F k. algorithm FibMergesort(L) {L is a list of items from a totally ordered set, whose length is a Fibonacci number F k } if L contains only 1 element, then return L else divide L into L 1 (the first F k 1 items) and L 2 (the remaining F k 2 items) sortedl 1 := FibMergesort(L 1 ) sortedl 2 := FibMergesort(L 2 ) sortedl := Merge(sortedL 1,sortedL 2 ) return sortedl Assuming that the divide step in FibMergesort takes constant time (no comparisons) and Merge behaves as described in the lecture notes, identify which of the following expressions most closely matches the total number of comparisons performed by FibMergesort when initially given a list of F k elements. (a) O(k log k) (b) O(k 2 ) (c) O(k F k ) (d) O(F k log k) (e) O(F 2 k ) Justify your answer. CS 70, Spring 2005, MT 1 7