CSE115/ENGR160 Discrete Mathematics 02/28/12

Slides:



Advertisements
Similar presentations
22C:19 Discrete Math Algorithms and Complexity
Advertisements

JAYASRI JETTI CHINMAYA KRISHNA SURYADEVARA
Problem: Give as many proofs as you can for the Pythagorean Theorem. i.e., a 2 + b 2 = c 2 holds for any right triangle with sides a & b and hypotenuse.
The Halting Problem of Turing Machines. Is there a procedure that takes as input a program and the input to that program, and the procedure determines.
Chapter 3 With Question/Answer Animations 1. Chapter Summary Algorithms Example Algorithms Algorithmic Paradigms Growth of Functions Big-O and other Notation.
Algorithms Chapter 3 Sec 3.1 &3.2 With Question/Answer Animations.
Prove the Impossible Sep 28 No program can check whether another program will run into infinite loop. x=0.
Cs333/cutler Greedy1 Introduction to Greedy Algorithms The greedy technique Problems explored –The coin changing problem –Activity selection.
Courtesy Costas Busch - RPI1 A Universal Turing Machine.
CPSC 411, Fall 2008: Set 12 1 CPSC 411 Design and Analysis of Algorithms Set 12: Undecidability Prof. Jennifer Welch Fall 2008.
Fall 2004COMP 3351 Recursively Enumerable and Recursive Languages.
CSE115/ENGR160 Discrete Mathematics 02/24/11 Ming-Hsuan Yang UC Merced 1.
Recursively Enumerable and Recursive Languages
CSE115/ENGR160 Discrete Mathematics 03/03/11 Ming-Hsuan Yang UC Merced 1.
CSE115/ENGR160 Discrete Mathematics 02/07/12
Algorithms: An Introduction
1 Uncountable Sets continued Theorem: Let be an infinite countable set. The powerset of is uncountable.
CSE115/ENGR160 Discrete Mathematics 03/10/11
Fall 2004COMP 3351 A Universal Turing Machine. Fall 2004COMP 3352 Turing Machines are “hardwired” they execute only one program A limitation of Turing.
Algorithms: An Introduction Section 3.1 of Rosen Spring 2011 CSCE 235 Introduction to Discrete Structures Course web-page: cse.unl.edu/~cse235 Questions:
1 Introduction to Computability Theory Lecture11: The Halting Problem Prof. Amos Israeli.
10/31/02CSE Greedy Algorithms CSE Algorithms Greedy Algorithms.
Lecture , 3.1 Methods of Proof. Last time in 1.5 To prove theorems we use rules of inference such as: p, p  q, therefore, q NOT q, p  q, therefore.
Introduction to Computer Science. A Quick Puzzle Well-Formed Formula  any formula that is structurally correct  may be meaningless Axiom  A statement.
February 17, 2015Applied Discrete Mathematics Week 3: Algorithms 1 Double Summations Table 2 in 4 th Edition: Section th Edition: Section th.
Algorithms Section 3.1. Problems and Algorithms In many domains there are key general problems that ask for output with specific properties when given.
Jessie Zhao Course page: 1.
Section 3.1: Proof Strategy Now that we have a fair amount of experience with proofs, we will start to prove more difficult theorems. Our experience so.
22C:19 Discrete Structures Algorithms and Complexity Fall 2014 Sukumar Ghosh.
Unsolvability and Infeasibility. Computability (Solvable) A problem is computable if it is possible to write a computer program to solve it. Can all problems.
1 Sections 1.5 & 3.1 Methods of Proof / Proof Strategy.
1 1 CDT314 FABER Formal Languages, Automata and Models of Computation Lecture 15-1 Mälardalen University 2012.
Algorithms April-May 2013 Dr. Youn-Hee Han The Project for the Establishing the Korea ㅡ Vietnam College of Technology in Bac Giang.
The Fundamentals: Algorithms, the Integers & Matrices.
CompSci 102 Discrete Math for Computer Science
Halting Problem Introduction to Computing Science and Programming I.
Chapter Algorithms 3.2 The Growth of Functions 3.3 Complexity of Algorithms 3.4 The Integers and Division 3.5 Primes and Greatest Common Divisors.
Section 3.1. Section Summary Properties of Algorithms Algorithms for Searching and Sorting Greedy Algorithms Halting Problem.
Example { 1 – –1} Use Bubble Sort (sort in increasing order} After first pass { –1 50} After Second Pass { } After.
1 Section 2.1 Algorithms. 2 Algorithm A finite set of precise instructions for performing a computation or for solving a problem.
CS 103 Discrete Structures Lecture 12
CS 3813: Introduction to Formal Languages and Automata Chapter 12 Limits of Algorithmic Computation These class notes are based on material from our textbook,
1 Turing’s Thesis. 2 Turing’s thesis: Any computation carried out by mechanical means can be performed by a Turing Machine (1930)
22C:19 Discrete Math Algorithms and Integers Fall 2010 Sukumar Ghosh.
Recursively Enumerable and Recursive Languages
Chapter 3 1 Kenneth Rosen, Discrete Mathematics and its Applications, 7th edition, McGraw Hill Instructor: Longin Jan Latecki,
Copyright © 2014 Curt Hill Algorithms From the Mathematical Perspective.
Chapter 3 With Question/Answer Animations 1. Chapter Summary Algorithms Example Algorithms Algorithmic Paradigms Growth of Functions Big-O and other Notation.
Ch03-Algorithms 1. Algorithms What is an algorithm? An algorithm is a finite set of precise instructions for performing a computation or for solving a.
Greedy Algorithms Prof. Kharat P. V. Department of Information Technology.
Chapter 3 With Question/Answer Animations 1. Chapter Summary Algorithm and Growth of Function (This slide) Algorithms - Sec 3.1 – Lecture 13 Example Algorithms.
Chapter 3 Sec 3.1 &3.2 With Question/Answer Animations 1.
1 Recursively Enumerable and Recursive Languages.
Recursively Enumerable and Recursive Languages. Definition: A language is recursively enumerable if some Turing machine accepts it.
1 A Universal Turing Machine. 2 Turing Machines are “hardwired” they execute only one program A limitation of Turing Machines: Real Computers are re-programmable.
Chapter 3 1 Kenneth Rosen, Discrete Mathematics and its Applications, 7th edition, McGraw Hill Instructor: Longin Jan Latecki,
Russell’s Paradox Is W in W? In words, W is the set that contains all the sets that don’t contain themselves. If W is in W, then W contains itself. But.
CSE15 Discrete Mathematics 03/06/17
Recursively Enumerable and Recursive Languages
CS 2210 Discrete Structures Algorithms and Complexity
A Balanced Introduction to Computer Science David Reed, Creighton University ©2005 Pearson Prentice Hall ISBN X Chapter 13 (Reed) - Conditional.
CS 2210 Discrete Structures Algorithms and Complexity
Applied Discrete Mathematics Week 6: Computation
Discrete Mathematics CMP-101 Lecture 12 Sorting, Bubble Sort, Insertion Sort, Greedy Algorithms Abdul Hameed
Greedy Algorithms.
Formal Languages, Automata and Models of Computation
CSCE 222 Discrete Structures for Computing
Algorithms Chapter 3 With Question/Answer Animations.
A Balanced Introduction to Computer Science David Reed, Creighton University ©2005 Pearson Prentice Hall ISBN X Chapter 13 (Reed) - Conditional.
CS 2210 Discrete Structures Algorithms and Complexity
Presentation transcript:

CSE115/ENGR160 Discrete Mathematics 02/28/12 Ming-Hsuan Yang UC Merced

Insertion sort Start with 2nd term Larger than 1st term, insert after 1st term Smaller than 1st term, insert before 1st term At this moment, first 2 terms in the list are in correct positions For 3rd term Compare with all the elements in the list Find the first element in the list that is not less than this element For j-th term Compare with the elements in the list

Example Apply insertion sort to 3, 2, 4, 1, 5 First compare 3 and 2  2, 3, 4, 1, 5 Next, insert 3rd item, 4>2, 4>3  2, 3, 4, 1, 5 Next, insert 4th item, 1<2  1, 2, 3, 4, 5 Next, insert 5th item, 5>1, 5>2, 5>3, 5>41, 2, 3, 4, 5

Insertion sort procedure insertion sort(a1, a2, …, an: real numbers with n≥2) i:=1 (left endpoint of search interval) j:=1 (right end point of search interval) for j:=2 to n begin i:=1 while aj>ai i:=i+1 m:=aj for k:=0 to j-i-1 aj-k:= aj-k-1 ai:= m end {a1 , a2, …, an are sorted}

Greedy algorithm Many algorithms are designed to solve optimization problems Greedy algorithm: Simple and naïve Select the best choice at each step, instead of considering all sequences of steps Once find a feasible solution Either prove the solution is optimal or show a counterexample that the solution is non-optimal

Example Given n cents change with quarters, dimes, nickels and pennies, and use the least total number of coins Say, 67 cents Greedy algorithm First select a quarter (leaving 42 cents) Second select a quarter (leaving 17 cents) Select a dime (leaving 7 cents) Select a nickel (leaving 2cnts) Select a penny (leaving 1 cent) Select a penny

Greedy change-making algorithm procedure change(c1, c2, …, cn: values of denominations of coins, where c1>c2>…>cn; n: positive integer) for i:=1 to r while n≥ci then add a coin with value ci to the change n:=n- ci end

Example Change of 30 cents If we use only quarters, dimes, and pennies (no nickels) Using greedy algorithm: 6 coins: 1 quarter, 5 pennies Could use only 3 coins (3 dimes)

Lemma 1 If n is a positive integer, then n cents in change using quarters, dimes, nickels, and pennies using the fewest coins possible has at most two dimes, at most one nickel, at most 4 pennies, and cannot have two dimes and a nickel The amount of change in dimes, nickels, and pennies cannot exceed 24 cents

Proof (Lemma) Proof by contradiction Show that if we had more than the specified number of coins of each type, we could replace them using fewer coins that have the same value If we had 3 dimes, could replace with 1 quarter and 1 nickel If we had 2 nickels, could replace them with 1 dime If we had 5 pennies, could replace them with 1 nickel If we had 2 dimes and 1 nickel, could replace them with 1 quarter Because we could have at most 2 dimes, 1 nickel, and 4 pennies, but we cannot have two dimes and a nickel, it follows 24 cents is the most we can have

Theorem Theorem: The greedy change-making algorithm produces change using the fewest coins possible Proof by contradiction Suppose that there is a positive integer n such that there is a way to make change for n cents using fewer coins (q’) than that of the greedy algorithm Let the number of quarters be q’, and the number of quarters used in the greedy algorithm be q

Proof First note q’ must be the same as q Note the greedy algorithm uses the most quarters possible, so q’≤q However, q’ ≮ q If q’ < q, we would need to make up 25 cents from dimes, nickels, and pennies in the optimal way to make change But this is impossible from Lemma 1

Proof As there must be the same number of quarters in the two algorithms The value of the dimes, nickels and pennies in these two algorithms must be the same, and their value is no more than 24 cents Likewise, there must be the same number of dimes, as the greedy algorithm used the most dimes possible and by Lemma 1, when change is made using the fewest coins possible, at most 1 nickel and a most 4 pennies are used, so that the most dimes possible are also used in the optimal way to make change Likewise, we have the same number of nickels, and finally the same number of pennies

The halting problem One of the most famous theorems in computer science There is a problem that cannot be solved using any procedure That is, we will show there are unsolvable problems The problem is the halting problem

The halting problem It asks whether there is a procedure that does this: It takes input as a computer program and input to the program, and determines whether the program will eventually stop when run with the input Useful to test certain things such as whether a program entered into an infinite loop

The halting problem First note that we cannot simply run a program and observe what it does to determine whether it terminates when run with the given input If the program halts, we have our answer But if it is still running after any fixed length of time has elapsed, we do not know whether it will never halt or we just did not wait long enough for it to terminate

Turing’s proof Halting problem is unsolvable Proof by contradiction The proof presented here is not completely rigorous Proof: Assume there is a solution to this halting problem called H(P,I) where P is a program and I is input H(P,I) outputs the string “halt” as output if H determines P stops when given I Otherwise, H(P,I) generates the string “loops forever” as output

Turing’s proof When a procedure is coded, it is expressed as a string of characters and can be interpreted as a sequence of bits A program can be used as data, and thus a program can be thought of as input to another program, or even itself H can take a program P as both of its inputs, which are a program and input to this program H should be able to determine if P will halt when it is given a copy of itself as input

Turing’s proof Construct a simple procedure K(P) that makes use of the output H(P,P) but does the opposite of H If the output of H(P,P) is “loops forever”, then K(P) halts IF the output of H(P,P) is “halt”, then K(P) loops forever

Turing’s proof Suppose we provide K as input to K We note that if the output of H(K,K) is “loops forever”, then by the definition of K, we see K(K) halts Otherwise, if the output of H(K,K) is “halt”, then by the definition of K we see that K(K) loops, in violation of what H tells us In both cases, we have contradiction Thus H cannot always give the correct answers No procedure solves the halting problem