This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: CMSC330 Fall 2009 Midterm #1 Solutions 1. (9 pts) Programming languages a. (3 pts) Explain the difference between interpretation and compilation. Interpretation evaluates a program one line at a time. Compilation translates a program into a different form that can be executed. b. (6 pts) Explain the difference between static and dynamic types. Write a small piece of Ruby code that relies on dynamic types. With static types, variable types are checked at compile time and thus generally remain fixed . With dynamic types, variable types are checked at run time (right before they are used), and can thus change during program execution. Example: x = 1 ; x = a ; 2. (15 pts) Regular expressions and finite automata a. (5 pts) Give a regular expression for all binary numbers (strings of 0s and 1s) with an odd number of 0s. Many possible answers, some examples are: 1* 0 (1*01*0)*1* 1* 0 1*(01*01*)* Basically a single 0, combined w/ RE for even # of 0s, mixed with lots of 1* b. (4 pts) Give a NFA that accepts all binary numbers (strings of 0s and 1s) with an even number of 0s. Many possible answers, one example: 1 1 1 1 c. (6 pts) Create a NFA for the regular expression ((ab|c)d)* using any method. Many possible answers, one example: b a d c b a d c 3. (18 pts) NFA to DFA Apply the subset construction algorithm to convert the following NFA to a DFA. Show the NFA states associated with each state in your DFA. the NFA states associated with each state in your DFA....
View Full Document
- Fall '08