m1-soln-fall10

m1-soln-fall10 - CMSC330 Fall 2010 Midterm #1 Solutions 1....

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

View Full Document Right Arrow Icon
CMSC330 Fall 2010 Midterm #1 Solutions 1. (12 pts) Ruby a. (6 pts) List 3 features of Ruby that are often found in scripting languages. Examples: interpreted, implicit declarations, dynamic types, built-in regular expressions, easy string processing b. (2 pts each) What is the output (if any) of the following Ruby programs? Write FAIL if code does not execute. i. puts “Found” if “College Park” =~ /([a-z]+)/ Output = Found ollege puts $1 ii. a = [ ] Output = nil nil 1 a[2] = 1 puts a iii. a = { 1 => 2 } Output = 2 a.keys.each{ |x| puts “#{a[x]}” } 2. (12 pts) Regular expressions and finite automata a. (4 pts) Give a regular expression for all binary numbers (strings of 0s and 1s) beginning and ending with 1 (e.g., 1, 111, 10011). 1 | 1(0|1)*1 b. (4 pts) Give a DFA for all binary numbers (strings of 0s and 1s) beginning and ending with 1 (including 1). 1 0 0 1 1 c. (4 pts) Explain why adding a not operator to the standard union , concatenation , and closure operators does not make regular expressions more powerful. Because any regular expression written using the not operator can also be written using just the union / concatenation / closure operators. [Optional] We know this because any DFA may be converted to the complement- DFA, then converted into a regular expression that does not use the not operator.
Background image of page 1

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

View Full DocumentRight Arrow Icon
3. (20 pts) RE to NFA to DFA
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 4

m1-soln-fall10 - CMSC330 Fall 2010 Midterm #1 Solutions 1....

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

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