Final Exam ~ notes On the semester’s material, with an attempt at bridging different topics. You may use two double-sided pages of notes (similar to before)…

Slides:



Advertisements
Similar presentations
Recursion Chapter 14. Overview Base case and general case of recursion. A recursion is a method that calls itself. That simplifies the problem. The simpler.
Advertisements

CATHERINE AND ANNIE Python: Part 3. Intro to Loops Do you remember in Alice when you could use a loop to make a character perform an action multiple times?
CSE341: Programming Languages Lecture 2 Functions, Pairs, Lists Dan Grossman Winter 2013.
CSE 311 Foundations of Computing I
Nondeterministic Finite Automata CS 130: Theory of Computation HMU textbook, Chapter 2 (Sec 2.3 & 2.5)
Lists in Lisp and Scheme a. Lists are Lisp’s fundamental data structures, but there are others – Arrays, characters, strings, etc. – Common Lisp has moved.
Finite Automata CPSC 388 Ellen Walker Hiram College.
1 Various Methods of Populating Arrays Randomly generated integers.
String and Lists Dr. Benito Mendoza. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list List.
1 Introduction to Computability Theory Lecture12: Decidable Languages Prof. Amos Israeli.
Finite Automata Great Theoretical Ideas In Computer Science Anupam Gupta Danny Sleator CS Fall 2010 Lecture 20Oct 28, 2010Carnegie Mellon University.
1 Introduction to Computability Theory Lecture13: Mapping Reductions Prof. Amos Israeli.
CS5371 Theory of Computation
Courtesy Costas Busch - RPI1 Non Deterministic Automata.
61 Nondeterminism and Nodeterministic Automata. 62 The computational machine models that we learned in the class are deterministic in the sense that the.
CS 302: Discrete Math II A Review. An alphabet Σ is a finite set (e.g., Σ = {0,1}) A string over Σ is a finite-length sequence of elements of Σ For x.
Snick  snack CPSC 121: Models of Computation 2010 Winter Term 2 DFAs in Depth Benjamin Israel Notes heavily borrowed from Steve Wolfman’s,
Fall 2006Costas Busch - RPI1 Non-Deterministic Finite Automata.
1 Non-Deterministic Automata Regular Expressions.
Introduction to Finite Automata Adapted from the slides of Stanford CS154.
CS Chapter 2. LanguageMachineGrammar RegularFinite AutomatonRegular Expression, Regular Grammar Context-FreePushdown AutomatonContext-Free Grammar.
Fall 2004COMP 3351 Another NFA Example. Fall 2004COMP 3352 Language accepted (redundant state)
Costas Busch - LSU1 Non-Deterministic Finite Automata.
Foundations of (Theoretical) Computer Science Chapter 1 Lecture Notes (Section 1.2: NFA’s) David Martin With some modifications.
FORMAL LANGUAGES, AUTOMATA AND COMPUTABILITY
1 Non-Deterministic Finite Automata. 2 Alphabet = Nondeterministic Finite Automaton (NFA)
CSE 311: Foundations of Computing Fall 2014 Lecture 23: State Minimization, NFAs.
(c) University of Washingtonhashing-1 CSC 143 Java Hashing Set Implementation via Hashing.
Comp. Eng. SW Lab II: FP with Scheme 1 Computer Eng. Software Lab II , Semester 2, Who I am: Andrew Davison CoE, WiG Lab Office.
Lists in Python.
REGULAR LANGUAGES.
Analyzing Complexity of Lists OperationSorted Array Sorted Linked List Unsorted Array Unsorted Linked List Search( L, x ) O(logn) O( n ) O( n ) Insert(
Analysis of Algorithms
EECS 110: Lec 5: List Comprehensions Aleksandar Kuzmanovic Northwestern University
Computabilty Computability Finite State Machine. Regular Languages. Homework: Finish Craps. Next Week: On your own: videos +
The building blocks of functional computing data, sequences conditionals recursion CS 121 today List Comprehensions map and applications.
DFA Minimization 1 2 Equivalent States Consider the accept states c and g. They are both sinks meaning that any string which ever reaches them is guaranteed.
MA/CSSE 474 Theory of Computation Enumerability Reduction.
Exam 1 Review EECS 483 – Lecture 15 University of Michigan Monday, October 30, 2006.
AP Computer Science edition Review 1 ArrayListsWhile loopsString MethodsMethodsErrors
Decidable languages Section 4.1 CSC 4170 Theory of Computation.
Fall 2002CS 150: Intro. to Computing1 Streams and File I/O (That is, Input/Output) OR How you read data from files and write data to files.
CMSC 330: Organization of Programming Languages Finite Automata NFAs  DFAs.
CMSC 330: Organization of Programming Languages Theory of Regular Expressions NFAs  DFAs.
CMSC 330: Organization of Programming Languages Maps and Folds Anonymous Functions.
INHERENT LIMITATIONS OF COMPUTER PROGAMS CSci 4011.
Week 10 - Friday.  What did we talk about last time?  Graph representations  Adjacency matrix  Adjacency lists  Depth first search.
TM Design Macro Language D and SD MA/CSSE 474 Theory of Computation.
CSE 311 Foundations of Computing I Lecture 28 Computability: Other Undecidable Problems Autumn 2011 CSE 3111.
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
CSCI 3130: Formal languages and automata theory Tutorial 1 Lee Chin Ho.
Nondeterministic Finite Automata (NFAs). Reminder: Deterministic Finite Automata (DFA) q For every state q in Q and every character  in , one and only.
Finite Automata Great Theoretical Ideas In Computer Science Victor Adamchik Danny Sleator CS Spring 2010 Lecture 20Mar 30, 2010Carnegie Mellon.
Recursion ITI 1121 N. El Kadri. Reminders about recursion In your 1 st CS course (or its equivalent), you have seen how to use recursion to solve numerical.
Haskell Chapter 5, Part II. Topics  Review/More Higher Order Functions  Lambda functions  Folds.
Computer Eng. Software Lab II , Semester 2, Who I am: Andrew Davison CoE, WiG Lab Office Functional Programming.
BINARY SEARCH CS16: Introduction to Data Structures & Algorithms Thursday February 12,
CSC-305 Design and Analysis of AlgorithmsBS(CS) -6 Fall-2014CSC-305 Design and Analysis of AlgorithmsBS(CS) -6 Fall-2014 Design and Analysis of Algorithms.
String and Lists Dr. José M. Reyes Álamo. 2 Outline What is a string String operations Traversing strings String slices What is a list Traversing a list.
MA/CSSE 474 Theory of Computation Decision Problems, Continued DFSMs.
(Universal Turing Machine)
CSE 105 theory of computation
Introduction to Functional Programming in Racket
CMSC201 Computer Science I for Majors Lecture 19 – Recursion
Search,Sort,Recursion.
CSE 311: Foundations of Computing
Introduction to Functional Programming in Racket
Announcements Quiz 5 HW6 due October 23
CSC 1051 – Data Structures and Algorithms I
Presentation transcript:

Final Exam ~ notes On the semester’s material, with an attempt at bridging different topics. You may use two double-sided pages of notes (similar to before)… Exam topics are available on the CS 60 website. A practice exam is available on the CS 60 website, as well. 3-hour take-home exam due Thursday at 5pm problems gratuitous backstories when possible always good to keep in mind: You can jump away from the code and explain your approach (or what you want things to do…) Partial credit is available -- more importantly, this can help you work out what needs to be done next!

6 Dynamic Programming Consider the equal-sum subset problem How to divide the values into two subsets ~ as equally as possible? use it or lose it! (for each item)

6 Dynamic Programming Consider the equal-sum subset problem How to divide the values into two subsets ~ as equally as possible? use it or lose it! (for each item) Just the make- change problem from Racket!

6 Dynamic Programming Consider the equal-sum subset problem Keep a table of all possible subset sums (so far)... Sum Element index

6 Dynamic Programming Recursive version (in Java) use it or lose it! (for each item)

6 Dynamic Programming Dynamic programming solution:

4 Prolog p( p( [0|R] ) :- subseq( [F|R], Warm up: true if L is a subsequence of M Another one: should accept 0 k followed by 1 k for any k >= 0 subseq( [4,2], [5,4,3,2,1] ). true. subseq( p( [0,0,1,1] ). p( [0,1,1] ). true. false. L M

3 DFAs & Regex (accepted -- considered transparent) (rejected -- two 1's in a four-sensor span) (accepted -- considered transparent) (accepted -- considered transparent) (accepted -- this piece is _really_ transparent!) 1 (accepted -- it does meet the definition: no more than one 1) 1 1 (rejected -- two 1's in a four- (or fewer) sensor span) (rejected -- three 1's in a four-sensor span) input stringsresults & explanation strings are rejected if there are two or more 1 s in any four-bit span; otherwise accepted Part A: Regular expression? Part B: DFA?

class Transition { int sourceState; // ss int destinationState; // ds int transitionChar; // tc } class NFA { int numStates; Transition[] T; boolean[] A; boolean run( Stack INPUT ) Start state is #0 0, 1, or -1 (for ) between 0 and numStates Input is here Does it accept or reject? Java NFAs an array indicating whether each state accepts or rejects an array of all the machine's transitions 2

boolean run( Stack INPUT ) 2-A NFAs in Java not 2B!

boolean run( Stack INPUT ) 2-A NFAs in Java not 2B! return run( INPUT, 0 ); // 0 is the start state! } boolean run( Stack INPUT, int curState ) {

boolean run( Stack INPUT ) 2-A NFAs in Java not 2B! return run( INPUT, 0 ); // 0 is the start state! } boolean run( Stack INPUT, int curState ) { // ASSUMING NO LAMBDA TRANSITIONS if (INPUT.isEmpty())

class Transition { int sourceState; // ss int destinationState; // ds int transitionChar; // tc } class NFA { int numStates; Transition[] T; boolean[] A; boolean run( Stack INPUT ) Start state is #0 0, 1, or -1 (for ) between 0 and numStates Input is here Does it accept or reject? Java NFAs an array indicating whether each state accepts or rejects an array of all the machine's transitions 2

boolean run( Stack INPUT ) 2-A NFAs in Java not 2B! return run( INPUT, 0 ); // 0 is the start state! } boolean run( Stack INPUT, int curState ) { // ASSUMING NO LAMBDA TRANSITIONS if (INPUT.isEmpty()) return A[curState]; int tc = INPUT.pop(); // next input character for (int i=0 ; i<T.length ; ++i) { // check transitions… if ( T[i].ss == __________ && T[i].tc == __________ ) {

boolean run( Stack INPUT ) 2-A NFAs in Java not 2B! return run( INPUT, 0 ); // 0 is the start state! } boolean run( Stack INPUT, int curState ) { // ASSUMING NO LAMBDA TRANSITIONS if (INPUT.isEmpty()) return A[curState]; int tc = INPUT.pop(); // next input character for (int i=0 ; i<T.length ; ++i) { if (T[i].ss == curState && T[i].tc == tc) { boolean result = run( copy(INPUT), T[i].ds ); if (result == true) return true; } // none were true, return false return false; }

2-B Java ~ inheritance You'd like to create a NTM. Should you make it a derived class from NFA? Nondeterministic Turing machine Transition? class NTM extends NFA class Transition { int sourceState; // ss int destinationState; // ds int transitionChar; // tc }

1-A (waldo w L) Scheme returns #t if w appears at any level in list L returns #f otherwise null? equal? list? cons list append review & include reminders… first three cases! (define (if (null? L) (if (equals? (if (list?

1-B (lotto T LoT) returns (name matches) for the best ticket in LoT Scheme LoT is a list of tickets; T is the winning ticket (("A" ) ("B" ) ("C" )) ( )

1-B (lotto T LoT) returns (name matches) for the best ticket in LoT Scheme LoT is a list of tickets; T is the winning ticket (("A" ) ("B" ) ("C" )) ( ) (define (lotto T LoT) (foldr compare '("no one" -1) (map (lambda (x) (score T x)) LoT))) "pushes" a binary operation "through" a list applies a unary operation to each element of a list

1-C Scheme (define (map f L) (if (null? L)

1-C Scheme (define (foldr f e L) (if (null? L) "pushes" a binary operation f "through" a list L

1-C Scheme Wikipedia! first rest first rest

0-A for (int i=N ; i>1 ; i=i/2) // i goes down to 1 for (int j=0 ; j<i ; ++j) // j goes up to i for (int k=0 ; k<i ; ++k) // k goes up to i /* one operation here */ Big-O loops

0-A for (int i=N ; i>1 ; i=i/2) // i goes down to 1 for (int j=0 ; j<i ; ++j) // j goes up to i for (int k=0 ; k<i ; ++k) // k goes up to i /* one operation here */ Big-O loops i i2i2

0-A for (int i=N ; i>1 ; i=i/2) // i goes down to 1 for (int j=0 ; j<i ; ++j) // j goes up to i for (int k=0 ; k<i ; ++k) // k goes up to i /* one operation here */ Big-O loops i i2i2 N N/2 i 1 OL Work N 2 (N/2) 2 i sum this column

0-B T(1) = 1 T(N) = kN 2 + 2T(N/2) Big-O recurrence relations "be kind; unwind"

0-B T(1) = 1 T(N) = kN 2 + 2T(N/2) Big-O recurrence relations "be kind; unwind"

Strategies? (1) review pages (2) slowed? use English other languages welcome, too, though we readers are more limited... (3) problem-solving more than memorization don't remember a function? – make it up don't remember some syntax? – make it up just add a note to that effect... Questions?

0-A for (int i=N ; i>1 ; i=i/2) // i goes down to 1 for (int j=0 ; j<i ; ++j) // j goes up to i for (int k=0 ; k<i ; ++k) // k goes up to i /* one operation here */ Big-O loops

0-A for (int i=N ; i>1 ; i=i/2) // i goes down to 1 for (int j=0 ; j<i ; ++j) // j goes up to i for (int k=0 ; k<i ; ++k) // k goes up to i /* one operation here */ Big-O loops i i2i2

0-A for (int i=N ; i>1 ; i=i/2) // i goes down to 1 for (int j=0 ; j<i ; ++j) // j goes up to i for (int k=0 ; k<i ; ++k) // k goes up to i /* one operation here */ Big-O loops i i2i2 N N/2 i 1 OL Work N 2 (N/2) 2 i sum this column

Good luck! See you M or F… on all of this week's work…

1-C Rex Wikipedia! first rest first rest

0-A for (int i=N ; i>1 ; i=i/2) // i goes down to 1 for (int j=0 ; j<i ; ++j) // j goes up to i for (int k=0 ; k<i ; ++k) // k goes up to i /* one operation here */ Big-O loops

0-A for (int i=N ; i>1 ; i=i/2) // i goes down to 1 for (int j=0 ; j<i ; ++j) // j goes up to i for (int k=0 ; k<i ; ++k) // k goes up to i /* one operation here */ Big-O loops i i2i2

0-A for (int i=N ; i>1 ; i=i/2) // i goes down to 1 for (int j=0 ; j<i ; ++j) // j goes up to i for (int k=0 ; k<i ; ++k) // k goes up to i /* one operation here */ Big-O loops i i2i2 N N/2 i 1 OL Work N 2 (N/2) 2 i sum this column

0-B T(1) = 1 T(N) = kN 2 + 2T(N/2) Big-O recurrence relations "be kind; unwind"

5 Uncomputability The Regular Expression Checker is uncomputable. REC YES, the input T's language of accepted strings is regular NO, the input T's language of accepted strings is not regular INPUT: A turing machine T

4 Prolog p( R ) :- subseq( L, M ) :- Warm up: true if L is a subsequence of M Another one: 0 k followed by 1 k for any k >= 0

3 DFAs & Regex (accepted -- considered transparent) (rejected -- two 1's in a four-sensor span) (accepted -- considered transparent) (accepted -- considered transparent) (accepted -- this piece is _really_ transparent!) 1 (accepted -- it does meet the definition: no more than one 1) 1 1 (rejected -- two 1's in a four- (or fewer) sensor span) (rejected -- three 1's in a four-sensor span) input stringsresults & explanation strings are rejected if there are two or more 1 s in any four-bit span; otherwise accepted Part A: Regular expression? Part B: DFA?

class Transition { int sourceState; // ss int destinationState; // ds int transitionChar; // tr } class NFA { int numStates; Transition[] T; boolean[] A; boolean run( Stack INPUT ) Start state is #0 0, 1, or -1 (for ) between 0 and numStates Input is here Does it accept or reject? 2 Java NFAs an array indicating whether each state accepts or rejects an array of all the machine's transitions

2-B Java ~ inheritance You'd like to create a NTM. Should you make it a derived class from NFA? Nondeterministic Turing machine Transition?

1-A waldo(w,L) Rex returns 1 if w appears at any level in list L returns 0 otherwise Here is a list of some useful Rex functions (other languages, too!) list(e,f,...) // makes a list from its inputs. [e,f,...] is often easier cons(f,R) // the same as [f|R] append(L,M) // concatenates two lists (inputs must be lists!) member(e,L) // 0 if e is not in L; 1 if e is in L reverse(L) // reverses L rmv1(e,L) // not built-in; from class -- removes one e from L removeAll(e,L) // not built-in; from hw#1 -- removes all e's from L length(L) // returns the length of L max(x,y) // returns the max of x and y -- does NOT take the max over a list min(x,y) // returns the min of x and y -- does NOT take the min over a list sort(L) // returns a sorted version of L first(L) // returns the first of L (similarly, second, third...) range(lo,hi) // returns [lo, lo+1, …, hi] (inclusive) higher-order functions: map(f,L) // applies f to each element of L. f takes one input. reduce(f,e,L) // "pushes" the binary operator f "through" L, starting at e keep(p,L) // retains those elements x in L that make p(x) true drop(p,L) // drops those elements x from L that make p(x) true some(p,L) // returns 1 iff there exists an x in L such that p(x) is true all(p,L) // returns 1 iff p(x) is true for all x in L

1-B lotto(WT, LoT) returns [name, matches] for the best ticket in LoT Rex WT is the winning ticket; LoT is a list of tickets. [1, 2, 3, 4, 5, 6] [ ["A", 2, 10, 12, 14, 16, 18], ["B", 2, 3, 40, 41, 42, 43], ["C", 1, 2, 3, 5, 15, 19] ]

1-B lotto(WT, LoT) returns [name, matches] for the best ticket in LoT Rex WT is the winning ticket; LoT is a list of tickets. [1, 2, 3, 4, 5, 6] lotto( WT, LoT ) => reduce( compare, [ "no one", -1 ], map(, LoT ) ); "pushes" a binary operation "through" a list applies a unary operation to each element of a list [ ["A", 2, 10, 12, 14, 16, 18], ["B", 2, 3, 40, 41, 42, 43], ["C", 1, 2, 3, 5, 15, 19] ]

1-C Rex map( f, L ) reduce( f, e, L ) map( f, reduce( f, e,

boolean run( Stack INPUT ) 2-A NFAs in Java

5 Uncomputability The f(42) == 60 checker is uncomputable. 42CH( f ) YES, f(42) == 60 NO, something (anything) else happens INPUT: A one-input function f OUTPUT: Assume it is computable ~ i.e., assume it exists. 42CH( f 1 )42CH( f 2 )42CH( f 3 ) def f 1 ( s ): return 60 def f 2 ( s ): return 17 def f 3 ( s ): while True: print 'hi'

5 Uncomputability def fun(P,w): def f 4 ( s ): P(w) return 17 b = 42CH( f 4 ) return b We write this function, fun: If fun is a haltchecker, we're done! Assume 42CH(f) exists. checks if f(42) == 60

5 Uncomputability Assume 42CH( f ) exists. def fun(P,w): def f 4 ( s ): P(w) return 60 b = 42CH( f 4 ) return b We write this function, fun: If fun is a haltchecker, we're done! checks if f(42) == 60

5 Uncomputability The Regular Expression Checker is uncomputable. RC( f ) YES, the input T's language of accepted strings is regular NO, the input T's language of accepted strings is not regular INPUT: A one-input function f OUTPUT: Assume it is computable ~ i.e., assume it exists. RC( f 1 )RC( f 2 )RC( f 3 ) def f 1 ( s ): return s==42 def f 2 ( s ): return hw12pr1(s) def f 3 ( s ): while True: pass

5 Uncomputability Assume RC( f ) exists. def fun(P,w): def f 4 ( s ): P(w) run hw12pr1 b = RC( f 4 ) return not b We write this function, fun: If fun is a haltchecker, we're done! checks if f accepts a regular language