MIT6_042JS10_lec08_sol - Massachusetts Institute of...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Massachusetts Institute of Technology 6.042J/18.062J, Spring ’10 : Mathematics for Computer Science February 19 Prof. Albert R. Meyer revised February 19, 2010, 1400 minutes Solutions to In-Class Problems Week 3, Fri. Problem 1. Let’s refer to a programming procedure (written in your favorite programming language —C++, or Java, or Python, . . . ) as a string procedure when it is applicable to data of type string and only returns values of type boolean . When a string procedure, P , applied to a string , s , returns True , we’ll say that P recognizes s . If R is the set of strings that P recognizes, we’ll call P a recognizer for R . (a) Describe how a recognizer would work for the set of strings containing only lower case Ro- man letter — a,b,. ..,z —such that each letter occurs twice in a row. For example, aaccaabbzz , is such a string, but abb , 00bb , AAbb , and a are not. (Even better, actually write a recognizer pro- cedure in your favorite programming language). Solution. All the standard programming languages have built-in operations for scanning the characters in a string. So simply write a procedure that checks an input string left to right, verify- ing that successive pairs of characters in the string are duplicated, lowercase roman characters. ACTUAL PROGRAM TBA A set of string s is called recognizable if there is a recognizer procedure for it. When you actually program a procedure, you have to type the program text into a computer system. This means that every procedure is described by some string of typed characters. If a string , s , is actually the typed description of some string procedure, let’s refer to that procedure as P s . You can think of P s as the result of compiling s . 1 In fact, it will be helpful to associate every string, s , with a procedure, P s ; we can do this by defining P s to be some fixed string procedure —it doesn’t matter which one —whenever s is not the typed description of an actual procedure that can be applied to string s. The result of this is that we have now defined a total function, f , mapping every string , s , to the set, f ( s ) , of string s recognized by P s . That is we have a total function, f : string → P ( string ) . (1) (b) Explain why the actual range of f is the set of all recognizable sets of strings. Creative Commons 2010, Prof. Albert R. Meyer . 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/27/2011 for the course CS 6.042J taught by Professor Prof.albertr.meyer during the Spring '11 term at MIT.

Page1 / 6

MIT6_042JS10_lec08_sol - Massachusetts Institute of...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online