3. Regular Expressions (12 points) (a) Which of the following strings are an exact match of the following Regular Expression? Mark all that apply. ( ) ^[A-Z][a-z0-9]+:([0-9]{3}|[CS330]+)$ A. Major: CS B. Age: 25 C. Class: CS330 D. Finitial: C E. None (b) Write a regular expression that accepts phone numbers of all the following formats and rejects everything else. You may assume that any X can be any digit. XXX-XXX-XXXX XXX-XXXXXXX XXXXXXXXX (XXX)-XXX-XXXX (XXX)-XXXXXXX (XXX)XXXXXXX
Added by Eric L.
Close
Step 1
The string must then be followed by either three digits or the string "CS330". Show more…
Show all steps
Your feedback will help us improve your experience
Sri K and 69 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Question 1) For the alphabet Σ={a,b}, give regular expression(s) for the language of strings that contain BOTH ab AND ba as substrings. In other words, select the regular expressions r such that L(r) ⊆ {uabvbaw | u, v, w ∈ Σ∗} ∪ {ubavabw | u, v, w ∈ Σ∗}. (Select all that apply from A to E) A) ababa B) (a|b)* (ab|ba) (a|b)* C) ((a|b)* a (a|b)* b (a|b)*) | ((a|b)* b (a|b)* a (a|b)*) D) ((a|b)* aa (a|b)* bb (a|b)*) | ((a|b)* bb (a|b)* aa (a|b)*) E) ((a|b)* ab (a|b)* ba (a|b)*) | ((a|b)* ba (a|b)* ab (a|b)*) Question 2) For the alphabet Σ={a, b}, give the regular expression(s) for language(s) whose strings end with EITHER ab OR ba. In other words, select the regular expression(s) r such that either L(r) ⊆ {uba | u ∈ Σ∗} ∪ {uab | u ∈ Σ∗}. (Select all that apply from A to E) A) (a|b)(a|b) B) (a|b)* ab (a|b)* C) ab (a|b)* (a|b)* ab D) ababa E) ((a|b)* aa (a|b)* bb) | ((a|b)* bb (a|b)* aa) Question 3) Which of the following sets is equivalent to the set {(a,b)∈(A×B)∣a∈C∧b∈D∖C}? Select all that apply from A to E. A) (A∩C)×(B∩(D∖C)) B) (A∪C)×(B∩(D∪C)) C) None of the given matches apply. D) A×(B∩(D∖C)) E) (A∩C)×((B∪D)∖C)
Sri K.
Akash M.
35 points: 10 points for each of a-c. 5 points for d. The language of strings over the alphabet = {0,1} which, in binary, represent even numbers, is a regular language. Show this by giving both (a) a regular expression and (b) drawing a finite state automaton (FSA) that recognizes strings from this language. Since regular languages are also context-free, give (c) a context-free grammar for this language. Finally, is the language of binary strings which represent odd numbers a regular language? If so, show why this is without resorting to regular expressions or FSAs. Note: You need not worry about leading zeros in any of the above. For example, 1010, 01010, 001010, and 0001010 all represent the number ten and are even. The regular expression (a) or context-free grammar (c) may generate strings with leading zeros (which represent only even numbers, of course), and the FSA (b) may recognize such strings.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Transcript
18,000,000+
Students on Numerade
Trusted by students at 8,000+ universities
Watch the video solution with this free unlock.
EMAIL
PASSWORD