Data Structures and Algorithms

Similar documents
Chapter 2. Mathematical Reasoning. 2.1 Mathematical Models

Announcements. Read Section 2.1 (Sets), 2.2 (Set Operations) and 5.1 (Mathematical Induction) Existence Proofs. Non-constructive

CSC165. Larry Zhang, October 7, 2014

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

CSE101: Design and Analysis of Algorithms. Ragesh Jaiswal, CSE, UCSD

Section 3.1: Direct Proof and Counterexample 1

MATH CSE20 Homework 5 Due Monday November 4

Discrete Mathematics. Spring 2017

Inference and Proofs (1.6 & 1.7)

Writing proofs for MATH 61CM, 61DM Week 1: basic logic, proof by contradiction, proof by induction

Proof Techniques (Review of Math 271)

COT 2104 Homework Assignment 1 (Answers)

Data Structures and Algorithms

CS1800: Mathematical Induction. Professor Kevin Gold

Math 13, Spring 2013, Lecture B: Midterm

means is a subset of. So we say A B for sets A and B if x A we have x B holds. BY CONTRAST, a S means that a is a member of S.

MATH 2200 Final LC Review

CS 360, Winter Morphology of Proof: An introduction to rigorous proof techniques

Divide and Conquer. Recurrence Relations

In-Class Soln 1. CS 361, Lecture 4. Today s Outline. In-Class Soln 2

Solving recurrences. Frequently showing up when analysing divide&conquer algorithms or, more generally, recursive algorithms.

Warm-up Quantifiers and the harmonic series Sets Second warmup Induction Bijections. Writing more proofs. Misha Lavrov

More examples of mathematical. Lecture 4 ICOM 4075

CS 173: Induction. Madhusudan Parthasarathy University of Illinois at Urbana-Champaign. February 7, 2016

PGSS Discrete Math Solutions to Problem Set #4. Note: signifies the end of a problem, and signifies the end of a proof.

Divide and Conquer Algorithms. CSE 101: Design and Analysis of Algorithms Lecture 14

Lecture 3. Big-O notation, more recurrences!!

CPSC 121: Models of Computation. Module 9: Proof Techniques (part 2) Mathematical Induction

15.082J & 6.855J & ESD.78J. Algorithm Analysis

Basics of Proofs. 1 The Basics. 2 Proof Strategies. 2.1 Understand What s Going On

Quiz 3 Reminder and Midterm Results

One-to-one functions and onto functions

At the start of the term, we saw the following formula for computing the sum of the first n integers:

Section Summary. Proof by Cases Existence Proofs

Chapter 3: Propositional Calculus: Deductive Systems. September 19, 2008

Clipping Algorithms; 8-5 (contd.) Computer Graphics. Spring CS4815

When we use asymptotic notation within an expression, the asymptotic notation is shorthand for an unspecified function satisfying the relation:

Discrete Mathematics and Probability Theory Fall 2016 Seshia and Walrand Note 2

Preparing for the CS 173 (A) Fall 2018 Midterm 1

Direct Proof and Counterexample I:Introduction

1 Direct Proofs Technique Outlines Example Implication Proofs Technique Outlines Examples...

CS1800: Strong Induction. Professor Kevin Gold

CS173 Running Time and Big-O. Tandy Warnow

Direct Proof and Counterexample I:Introduction. Copyright Cengage Learning. All rights reserved.

Divide and Conquer Algorithms

CSE 311 Lecture 28: Undecidability of the Halting Problem. Emina Torlak and Kevin Zatloukal

Mathematical Reasoning Rules of Inference & Mathematical Induction. 1. Assign propositional variables to the component propositional argument.

Contents. Counting Methods and Induction

Writing proofs for MATH 51H Section 2: Set theory, proofs of existential statements, proofs of uniqueness statements, proof by cases

Proof by Contradiction

Proof by contrapositive, contradiction

MATH 55 - HOMEWORK 6 SOLUTIONS. 1. Section = 1 = (n + 1) 3 = 2. + (n + 1) 3. + (n + 1) 3 = n2 (n + 1) 2.

COE428 Notes Week 4 (Week of Jan 30, 2017)

CS 2110: INDUCTION DISCUSSION TOPICS

When we use asymptotic notation within an expression, the asymptotic notation is shorthand for an unspecified function satisfying the relation:

1 Closest Pair of Points on the Plane

An analogy from Calculus: limits

Winter Camp 2009 Number Theory Tips and Tricks

Divide and Conquer. Maximum/minimum. Median finding. CS125 Lecture 4 Fall 2016

Chapter 1: The Logic of Compound Statements. January 7, 2008

Methods for solving recurrences

ALGEBRA. 1. Some elementary number theory 1.1. Primes and divisibility. We denote the collection of integers

Math 38: Graph Theory Spring 2004 Dartmouth College. On Writing Proofs. 1 Introduction. 2 Finding A Solution

CS173 Lecture B, November 3, 2015

Writing Mathematical Proofs

Data Structures and Algorithms

7.11 A proof involving composition Variation in terminology... 88

MATH 2200 Final Review

Divide and Conquer Algorithms

Math 3361-Modern Algebra Lecture 08 9/26/ Cardinality

STRATEGIES OF PROBLEM SOLVING

CSCE 222 Discrete Structures for Computing. Proofs. Dr. Hyunyoung Lee. !!!!! Based on slides by Andreas Klappenecker

Notes from How to Prove it: A Structured Approach by Daniel J. Velleman

MI 4 Mathematical Induction Name. Mathematical Induction

Lecture 17: Trees and Merge Sort 10:00 AM, Oct 15, 2018

x P(x) x P(x) CSE 311: Foundations of Computing announcements last time: quantifiers, review: logical Inference Fall 2013 Lecture 7: Proofs

Module 9: Mathematical Induction

USA Mathematical Talent Search Round 2 Solutions Year 27 Academic Year

MATH10040: Numbers and Functions Homework 1: Solutions

CS 70 Discrete Mathematics and Probability Theory Fall 2016 Seshia and Walrand Midterm 1 Solutions

CMPSCI 250: Introduction to Computation. Lecture 11: Proof Techniques David Mix Barrington 5 March 2013

Lecture 13. More dynamic programming! Longest Common Subsequences, Knapsack, and (if time) independent sets in trees.

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

N/4 + N/2 + N = 2N 2.

An Introduction to Proofs in Mathematics

Lecture Notes on Inductive Definitions

Math 31 Lesson Plan. Day 2: Sets; Binary Operations. Elizabeth Gillaspy. September 23, 2011

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

HOW TO CREATE A PROOF. Writing proofs is typically not a straightforward, algorithmic process such as calculating

3 The language of proof

The following techniques for methods of proofs are discussed in our text: - Vacuous proof - Trivial proof

Fall 2017 November 10, Written Homework 5

Discrete Mathematics and Probability Theory Fall 2012 Vazirani Note 1

CMPSCI 311: Introduction to Algorithms Second Midterm Exam

MCS-236: Graph Theory Handout #A4 San Skulrattanakulchai Gustavus Adolphus College Sep 15, Methods of Proof

Lesson 3-1: Solving Linear Systems by Graphing

MATH 220 (all sections) Homework #12 not to be turned in posted Friday, November 24, 2017

a 2 = ab a 2 b 2 = ab b 2 (a + b)(a b) = b(a b) a + b = b

Outline. 1 Merging. 2 Merge Sort. 3 Complexity of Sorting. 4 Merge Sort and Other Sorts 2 / 10

MA008/MIIZ01 Design and Analysis of Algorithms Lecture Notes 3

Transcription:

Data Structures and Algorithms Spring 2017-2018

Outline Announcements 1 Announcements 2 3 Recap Mergesort

Of Note Labs start in Week02 in CS305b Do you have linux account? Lab times: Fri. 15.00, 16.00 Tutes start tomorrow: SG16, 13.00 Study skills seminars take place next week; see Lect01 for more details

Of Note Labs start in Week02 in CS305b Do you have linux account? Lab times: Fri. 15.00, 16.00 Tutes start tomorrow: SG16, 13.00 Study skills seminars take place next week; see Lect01 for more details

Of Note Labs start in Week02 in CS305b Do you have linux account? Lab times: Fri. 15.00, 16.00 Tutes start tomorrow: SG16, 13.00 Study skills seminars take place next week; see Lect01 for more details

Four Main When trying to formally establish some claim, the main proof techniques that we use are: induction contradiction counterexample contrapositive

Outline Announcements 1 Announcements 2 3 Recap Mergesort

Proof by Announcements Suppose we have a theorem quantified by a variable n proof by induction proves that the theorem is true for n = K + 1 by using the fact that the theorem is true for some number K only works for proving things about integers or other discrete objects in the inductive step, we show that the theorem is true for n = K + 1 assuming that it is true for n = K for this to work we also need a starting point or, base case Prove n (2i 1) = n 2, n > 0 i=1

Proof by (contd.) Prove 5n 1 < n 2, n 5 Warning: Inequality doesn t hold for 0 < n 4, so we have to build a restriction in to our theorem Red, curved line is a plot of n 2 ; green, straight line is 5n 1

Outline Announcements 1 Announcements 2 3 Recap Mergesort

Proof by Proof by contradiction relies on fact that everything either is or isn t true To prove some fact, we attempt to prove the opposite hypothesis instead By encountering a contradiction somewhere in this proof it shows that our new hypothesis must be false, meaning that the original was true So to prove the theorem A B, we would attempt to prove the opposite, A B

Proof by (contd.) To Prove There are an infinite number of prime numbers. Proof: Suppose this is not true. Then we assume there are only a finite number of primes, say, m of them. Then we can write these m numbers down: p 1, p 2, p 3,..., p m where p m is the largest prime possible. (Background fact: every non-prime number can be broken into its factors ; this can be done to each of these factors (repeatedly) until you have only prime numbers.) Now consider the number K = 1 + p 1. p 2. p 3.. p m. This number cannot have any divisor (a number that divides it cleanly) so it must be prime. But K > p m, which contradicts our assumption. Each step in this proof is sound, so our modified hypothesis is unsound.

Outline Announcements 1 Announcements 2 3 Recap Mergesort

(Dis)Proof by Can only use this to prove a statement false. Find an instance where the theorem / claim is false. Prove 5n 1 < n 2, n > 0 Proof: When n = 1, 5 1 1. (Theorem would have been true if condition was n 5.) Prove The sun always shines in Limerick. Proof: Take a look outside: the sun isn t shining!

Outline Announcements 1 Announcements 2 3 Recap Mergesort

Proof by To prove A B, prove instead B A Both are equivalent; technique is often called Modus Tolens From Final Exam, 2001-2002 Prove that if every vertex in a graph G = (V, E) has degree greater than 1, then there must be some cycle in the graph. a a d b d b c A cyclic graph A tree Note carefully what the theorem says: if every vertex has degree of two, or more, then there must be a cycle, yet even if some vertices have degree 1, there could be still a cycle (pic. on left). c

Proof by (contd.) Proof (1): (Follow your nose.) If every vertex has degree 2 or more, then it has at least two edges Pick any vertex v as a starting point, mark it and leave the vertex on one of its (more than one) edges This takes us to a new vertex and, since its degree is greater than 1, we can exit it on a different edge, also

Proof by (contd.) Keep doing this, marking each vertex as we go, and never walking across an edge twice Since there are a finite number of vertices, we must visit some vertex that we ve seen before This is the cycle! The trouble with walking to vertices of degree 1 (C below): C A B

Proof by (contd.) Keep doing this, marking each vertex as we go, and never walking across an edge twice Since there are a finite number of vertices, we must visit some vertex that we ve seen before This is the cycle! The trouble with walking to vertices of degree 1 (C below): C A B

Proof by (contd.) Proof (2): (Use every trick in the book.) If we abbreviate there must be some cycle in the graph by cyc(g) (G has a cycle) then we can write the theorem as: v V, d(v) 2 cyc(g) The contrapositive of this is if there is no cycle in G then there must be some vertex v whose degree is not 2 or more, which can be written cyc(g) v V, d(v) 2 cyc(g) v V, d(v) 1

Proof by (contd.) To prove this, we will look for a contradiction in proving the opposite cyc(g) v V, d(v) 2 This cannot be true because the previous tree clearly has no cycle yet the leaves have degree 1. Thus, the following is false meaning, both and are true. cyc(g) v V, d(v) 2 cyc(g) v V, d(v) 2 v V, d(v) 2 cyc(g)

Outline Announcements Recap Mergesort 1 Announcements 2 3 Recap Mergesort

Recap Mergesort Recap To solve a problem recursively we break the problem in to one or more subproblems that have the same description as the original Each of the subproblems can then be solved using the algorithm There will likely be other housekeeping to do as well as part of the recursive call

Outline Announcements Recap Mergesort 1 Announcements 2 3 Recap Mergesort

Mergesort Requires Recap Mergesort To sort an array, split the array in two, sort the two halves (independently) and then merge the two halves in to one. void mergesort(int arr[], int lo, int hi) { // sort array arr, from lo to hi if (lo >= hi) return; // base case int mid = (lo + hi) / 2; mergesort(arr, lo, mid); mergesort(arr, mid+1, hi); } merge_halves(arr, lo, mid, hi); // housekeeping

The Merge in Mergesort Recap Mergesort // merge_halves merges sorted halves arr[lo..mid] // and arr[mid+1..hi] to give the sorted arr[lo.. void merge_halves(int arr[], int lo, int mid, int hi) { // homework exercise }