MA/CSSE 473 Day 19 Subset Generation. MA/CSSE 473 Day 19 HW 7 due today Exam 1 Thursday There will be significant time for your questions in tomorrow's.

Slides:



Advertisements
Similar presentations
Recursion and Induction
Advertisements

Chapter 6 Advanced Counting 6.1 Recurrence Relations.
Discrete Mathematics Math 6A Homework 9 Solution.
Greedy Algorithms Greed is good. (Some of the time)
FORMAL LANGUAGES, AUTOMATA, AND COMPUTABILITY
8.4 Closures of Relations. Intro Consider the following example (telephone line, bus route,…) abc d Is R, defined above on the set A={a, b, c, d}, transitive?
1 Languages. 2 A language is a set of strings String: A sequence of letters Examples: “cat”, “dog”, “house”, … Defined over an alphabet: Languages.
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
Costas Busch - RPI1 Single Final State for NFAs. Costas Busch - RPI2 Any NFA can be converted to an equivalent NFA with a single final state.
Lecture 38 CSE 331 Dec 7, The last few days Today: Solutions to HW 9 (end of lecture) Wednesday: Graded HW 9 (?), Sample final, Blog post on the.
CSE115/ENGR160 Discrete Mathematics 04/03/12 Ming-Hsuan Yang UC Merced 1.
1 Module 9 Recursive and r.e. language classes –representing solvable and half-solvable problems Proofs of closure properties –for the set of recursive.
Fall 2004COMP 3351 Single Final State for NFA. Fall 2004COMP 3352 Any NFA can be converted to an equivalent NFA with a single final state.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
1 Languages and Finite Automata or how to talk to machines...
1 Single Final State for NFAs and DFAs. 2 Observation Any Finite Automaton (NFA or DFA) can be converted to an equivalent NFA with a single final state.
CS5371 Theory of Computation Lecture 1: Mathematics Review I (Basic Terminology)
Costas Busch - RPI1 Mathematical Preliminaries. Costas Busch - RPI2 Mathematical Preliminaries Sets Functions Relations Graphs Proof Techniques.
Courtesy Costas Busch - RPI1 Mathematical Preliminaries.
16.Greedy algorithms Hsu, Lih-Hsing. Computer Theory Lab. Chapter 16P An activity-selection problem Suppose we have a set S = {a 1, a 2,..., a.
Recursion and Induction Themes –Recursion –Recurrence Definitions –Recursive Relations –Induction (prove properties of recursive programs and objects defined.
MA/CSSE 473 Day 22 Gray Code More Decrease and Conquer Algorithms No class Day 22 in because of Abby's broken arm.
Approaches to Problem Solving greedy algorithms dynamic programming backtracking divide-and-conquer.
MA/CSSE 473 Day 13 Permutation Generation. MA/CSSE 473 Day 13 HW 6 due Monday, HW 7 next Thursday, Student Questions Tuesday’s exam Permutation generation.
CSE 311 Foundations of Computing I Lecture 15 Recursive Definitions and Structural Induction Autumn 2011 CSE 3111.
CSE 311 Foundations of Computing I Lecture 16 Recursively Defined Sets and Structural Induction Spring
MA/CSSE 473 Day 02 Some Numeric Algorithms and their Analysis.
Mathematical Preliminaries Strings and Languages Preliminaries 1.
MA/CSSE 474 Theory of Computation DFSM Canonical Form Proof of NDFSM  DFSM ALGORITHM (as much as we have time for) This version includes the "answers"
Data Structures and Algorithms A. G. Malamos
Mathematical Preliminaries (Hein 1.1 and 1.2) Sets are collections in which order of elements and duplication of elements do not matter. – {1,a,1,1} =
Fall Week 4 CSCI-141 Scott C. Johnson.  Computers can process text as well as numbers ◦ Example: a news agency might want to find all the articles.
Design of Algorithms using Brute Force Approach. Primality Testing (given number is n binary digits)
MA/CSSE 473 Day 14 Permutations wrap-up Subset generation (Horner’s method)
MA/CSSE 473 Day 18 Permutations by lexicographic order number.
CSCI 2670 Introduction to Theory of Computing Instructor: Shelby Funk.
Mathematical Preliminaries. Sets Functions Relations Graphs Proof Techniques.
Fall 2005Costas Busch - RPI1 Mathematical Preliminaries.
Prof. Busch - LSU1 Mathematical Preliminaries. Prof. Busch - LSU2 Mathematical Preliminaries Sets Functions Relations Graphs Proof Techniques.
Chapter 5: Sequences, Mathematical Induction, and Recursion 5.9 General Recursive Definitions and Structural Induction 1 Erickson.
MA/CSSE 474 Theory of Computation Decision Problems DFSMs.
Language: Set of Strings
Mathematical Preliminaries
Lecture 3 Combinational Circuits
CSCI 2670 Introduction to Theory of Computing September 13.
Grammars A grammar is a 4-tuple G = (V, T, P, S) where 1)V is a set of nonterminal symbols (also called variables or syntactic categories) 2)T is a finite.
Mathematical Induction Section 5.1. Climbing an Infinite Ladder Suppose we have an infinite ladder: 1.We can reach the first rung of the ladder. 2.If.
8.4 Closures of Relations Definition: The closure of a relation R with respect to property P is the relation obtained by adding the minimum number of.
1 Mathematical Preliminaries. 2 Sets Functions Relations Graphs Proof Techniques.
 A sequence is a list of objects arranged in a specific order.  A sequence in computer science is known as an array. An array hold objects of the same.
Recursion and Induction Themes –Recursion –Recurrence Definitions –Recursive Relations –Induction (prove properties of recursive programs and objects defined.
Transparency No. 1 Formal Language and Automata Theory Homework 1.
MA/CSSE 473 Day 21 In , Day 21 was the exam.
Theory of Computational Complexity Probability and Computing Ryosuke Sasanuma Iwama and Ito lab M1.
Week 8 - Wednesday.  What did we talk about last time?  Relations  Properties of relations  Reflexive  Symmetric  Transitive.
Section Recursion 2  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
1 Recursive Definitions and Structural Induction CS/APMA 202 Rosen section 3.4 Aaron Bloomfield.
Section Recursion  Recursion – defining an object (or function, algorithm, etc.) in terms of itself.  Recursion can be used to define sequences.
Greedy Algorithms. p2. Activity-selection problem: Problem : Want to schedule as many compatible activities as possible., n activities. Activity i, start.
1 Proving Properties of Recursive List Functions CS 270 Math Foundations of CS Jeremy Johnson.
MA/CSSE 474 Theory of Computation Decision Problems, Continued DFSMs.
(Proof By) Induction Recursion
MA/CSSE 473 Day 15 Return Exam Student questions Towers of Hanoi
Languages.
CSE 311: Foundations of Computing
CSE 311 Foundations of Computing I
Chapter 16: Greedy algorithms Ming-Te Chi
Recall Brute Force as a Problem Solving Technique
Languages Fall 2018.
Terminology and Symbols
Presentation transcript:

MA/CSSE 473 Day 19 Subset Generation

MA/CSSE 473 Day 19 HW 7 due today Exam 1 Thursday There will be significant time for your questions in tomorrow's class HW 8 has grace days to allow you to finish it early in the break if you wish. HW9 will be due on Tuesday after the break, HW 10 on Friday With HW 11, we get back to Monday-Thursday schedule Student Questions Subset Generation

Preliminary: Reversing a string Definition of reverse: –The reverse of the empty string is the empty string –If a is a character and w is a string, (aw) R = w R a. Lemma: –For any two strings, x and y, (xy) R = y R x R Proof by induction on length of y –Base case: y is empty –Otherwise, y = za for some string z and some character a. Assume by induction that the property is true for the shorter string z.

All Subsets of a Set Sample Application: –Solving the knapsack problem –In the brute force approach, we try all subsets If A is a set, the set of all subsets is called the power set of A, and often denoted 2 A If A is finite, then So we know how many subsets we need to generate.

Generating Subsets of {a 1, …, a n } Decrease by one: Generate S n-1, the collection of the 2 n-1 subsets of {a 1, …, a n-1 } Then S n = S n-1  { s  {a n } : s  S n-1 } Another approach: –Each subset of {a 1, …, a n } corresponds to an bit string of length n, where the i th bit it 1 iff a i is in the subset

Another approach: Each subset of {a 1, …, a n } corresponds to an bit string of length n, where the i th bit is 1 if and only if a i is in the subset def allSubsets(s): n = len(s) subsets=[] for i in range(2**n): subset = [] current = i for j in range (n): if current % 2 == 1: subset += [s[j]] current /= 2 subsets += [subset] return subsets Output: [[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3]]

Gray Codes Named for Frank Gray An ordering of the 2 n n-bit binary codes such that any two consecutive codes differ in only one bit Example: 000, 001, 011, 010, 110, 111, 101, 100 Note also that only one bit changes between the last code and the first code. A Gray code can be represented by its transition sequence: indicates which bit changes each time In above example: 0, 1, 0, 2, 0, 1, 0 Traversal of the edges of a (hyper)cube. In terms of subsets, the transition sequence tells which element to add or remove from one subset to get the next subset

Recursively Generating a Gray Code Binary Reflected Gray Code T 1 = 0 T n+1 = T n, n, T n reversed Show by induction that T n reversed = T n Thus T n+1 = T n, n, T n

Iteratively Generating a Gray Code We add a parity bit, p. Set all bits (including p) to 0. Q4 * Based on Knuth, Volume 4, Fascicle 2, page 6.

Quote of the Day There are 10^11 stars in the galaxy. That used to be a huge number. But it's only a hundred billion. It's less than the national deficit! We used to call them astronomical numbers. Now we should call them economical numbers. - Richard FeynmanRichard Feynman