ENEE 222 EXAM 2: SAMPLE PROBLEMS
Calculators will not be allowed.
The following formulas will be given on the exam sheet:
Time Domain
x[n] =
1
N
N 1
X [k ]ej (2/N )kn
Frequency Domain
N 1
X [k ] =
x[n]ej (2/N )kn
n=0
k=0
1
x = VX X = Wx
N
x + y X + Y
x

CMSC351 - Fall 2014, Homework #6
Due: December 12th at the start of class
PRINT Name:
Grades depend on neatness and clarity.
Write your answers with enough detail about your approach and concepts used,
so that the grader will be able to understand it ea

Reconsider These Three String Operations
CMSC 330: Organization of
Programming Languages
"hello".index("l", 0)
return index of the first occurrence of string in s, starting at n
"hello".sub("h", "j")
replace first occurrence of "h" by "j" in string
u

Standard Library: Hash
CMSC 330: Organization of
Programming Languages
A hash acts like an associative array, in which
elements can be indexed by any types of
values, not necessarily just integers
every Ruby object can be used as a hash key,
because the

Classes and Objects in Ruby
CMSC 330: Organization of
Programming Languages
class Point
def initialize(x, y)
@x = x
@y = y
end
def addX(x)
@x += x
end
Ruby, Part 2
class contains method/
constructor definitions
constructor definition
instance variables pr

Course Goal
CMSC 330: Organization of
Programming Languages
Learn how programming languages work
Broaden your language horizons
Different programming languages
Different language features and tradeoffs
Introduction
Study how languages are implemented

CMSC 330
Automata constructions solutions
Fall 2012
Of course automata are not unique, so the ones you create for some parts could be dierent.
1. If there any path for the string that ends at a nal state of the NFA.
2. 2n
3. (010) (0 | )
0
0
1
4.
S0
S1
0

CMSC 330
Automata transformations
Fall 2012
1. When does an NFA accept a string?
2. How long could it take to reduce a NFA with n states and t transitions to a DFA?
3. What language (or set of strings) is accepted by the following NFA?
1
S1
S2
0
0
0
S0
S3

CMSC 330
Finite automata solutions
Fall 2012
1. Note that dierent solutions are possible.
a
a
a
b
b
a.
ba
b
b
a
dead
state
a
b
b
a
b
a
b
a
b
b.
a
a
b
b
a
b
b
a
b
a
c.
d.
a
b
a
b
dead
state
a
b
a
a
a
b
a
a
e.
aa
bb
bb
aa
b
b
b
Note that when a language is

CMSC 330, Practice Problems 1 (SOLUTIONS)
1. Programming languages
a. Explain how goals for programming languages have changed since the 1960s.
Shifted from efficiency to ease-of-programming
b. List 2 desirable attributes for a programming language where

CMSC 330, Practice Problems 2 (SOLUTIONS)
1. Regular expressions and languages
a. From the perspective of formal language theory, what is a language?
Set of strings
b. Given the language A = cfw_aa, c and B = cfw_b, what is the language AB?
cfw_aab, cb
c.

CMSC 330, Fall 2009, Practice Problem 3 Solutions
1.
Context Free Grammars
a. List the 4 components of a context free grammar.
Terminals, non-terminals, productions, start symbol
b. Describe the relationship between terminals, non-terminals, and productio

CMSC 330, Fall 2009, Practice Problem 4 Solutions
1. OCaml and Functional Programming
a. Define functional programming
Programs are expression evaluations
b. Define imperative programming
Programs change the value of variables
c. Define higher-order funct

CMSC330 Fall 2009 Practice Problems 5 Solutions
1. Lambda calculus
Make all parentheses explicit in the following -expressions
a. x.xz y.xy
( x.(x z) ( y.(x y)
b. ( x.xz) y.w w.wyzx
( x.(x z) ( y.(w ( w.(w y) z) x)
c. x.xy x.yx
( x.(x y) ( x.(y x)
Find al

Introduction
CMSC 330: Organization of
Programming Languages
Ruby is an object-oriented, imperative scripting
language
I wanted a scripting language that was more powerful than
Perl, and more object-oriented than Python. That's why I
decided to design m

A Few Questions about Regular Expressions
CMSC 330: Organization of
Programming Languages
What does a regular expression represent?
just a set of strings
What are the basic components of r.e.'s?
e.g., we saw that e+ is the same as ee*
How are r.e.'s

Background
CMSC 330: Organization of
Programming Languages
1973 ML developed at Univ. of Edinburgh
Part of a theorem proving system LCF
The Logic of Computable Functions
SML/NJ (Standard ML of New Jersey)
http:/www.smlnj.org
Developed at Bell Labs a

CMSC 330
Finite automata
Fall 2012
1. For each of the following problems construct a deterministic nite automaton that describes or recognizes
the language given. Write all DFAs in the form of a transition diagram. The underlying alphabet is
= cfw_a, b.

CMSC 330
Formal languages and regular expressions
solutions
Fall 2012
1. a. cfw_ a, aa, aaa ( A)
b. cfw_ aa, aaa, aaaa, aaaaa, aaaaaa
c. cfw_ a, aa, aaa, aaaa, aaaaa, aaaaaa
d. cfw_ , a, aa, aaa, aaaa, aaaaa, aaaaaa, . . .
e. cfw_ bb ( B)
f. cfw_ bb

CMSC 330
Formal languages and regular expressions
Fall 2012
1. Consider the languages or sets of strings A = cfw_ a, aa, aaa and B = cfw_ bb . Show the languages denoted
by each of the following:
a. A1
e. B1
i. B
b. A2
f. B2
j. (AB)2
c. A A2
g. B3
k. (A

CMSC 330 Ruby and Ruby Regular Expressions Solutions
Fall 2012
1. a. Shifted from eciency to ease-of-programming
b.
Naturalness of application - text processing is easier in Ruby
Cost of use Small Ruby programs are simpler/quicker to write
c. Interpreta

1
CMSC 330
Exam #1 practice questions #1
Fall 2012
Do not open this exam until you are told. Read these instructions:
1. This is a closed book exam. No notes or other aids are allowed. If you have a question during the
exam, please raise your hand. Each q

1
CMSC 330
Exam #1 practice questions #2
Fall 2012
Do not open this exam until you are told. Read these instructions:
1. This is a closed book exam. No notes or other aids are allowed.
2. You must turn in your exam immediately when time is called at the e

CMSC 330
Exam #1 practice questions #1 solutions
Fall 2012
1. [16 pts.]
a. Heres an example illustraing that Ruby has dynamic typing:
x= 330
x= "CMSC 330 is lots of fun!"
Note that dynamic typing isnt the same thing as implicit variable declarations. Ruby

CMSC 330
Exam #1 practice questions #2 solutions
Fall 2012
1. [20 pts.] Short answer.
a. [5 pts.] A formal parameter is the name for a parameter as used in the body of a method or function.
An actual parameter is the argument that is passed in at a method

CMSC 330
Ruby and Ruby Regular Expressions
Fall 2012
1. Programming languages
a. Explain how goals for programming languages have changed since the 1960s.
b. List two desirable attributes for a programming language where Ruby is better than C. Explain
why

Reducing Regular Expressions to NFAs
CMSC 330: Organization of
Programming Languages
Goal: Given regular expression e, construct
NFA <e> = (, Q, q0, F, ) that accepts the
same language
invariant: |F| = 1 in our NFAs
Base case: a
Finite Automata, con't.

NFA DFA Example 3
CMSC 330: Organization of
Programming Languages
NFA
DFA
cfw_B,D,E
a
cfw_A,E
b
a
a
cfw_E
b
b
cfw_C,D
Finite Automata, con't.
R = cfw_ cfw_A,E,
cfw_B,D,E, cfw_C,D,
cfw_E
2
Equivalence of DFAs and NFAs
Equivalence of DFAs and NFAs (cont.

Implementing Regular Expressions
CMSC 330: Organization of
Programming Languages
We can implement regular expressions by
turning them into a finite automaton
a machine for recognizing a language
Finite Automata
CMSC 330
Example
Start state
Transition on