ECS 120 Midterm 1

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Which of the following regular expressions decides the subset of {0,1}* of strings that begin and end with the same symbol? 0(0∪1)*0 ∪ 1(0∪1)*1 (0∪1)* 0 ∪ 1 ∪ 0(0∪1)*0 ∪ 1(0∪1)*1 (0∪1)(0∪1)*(0∪1)

0 ∪ 1 ∪ 0(0∪1)*0 ∪ 1(0∪1)*1

Define the language C = { w∈{0,1}* | #(0,w) = #(1,w) }. Let x = 01 and y = 110. Which of the following are separating extensions for x and y? 01 ε 0 x and y have no separating extension.

01 ε 0

Define the language B = { 0ⁿ1ⁿ | n∈ℕ }. Let x = 0 and y = 00. Which of the following are separating extensions for x and y? 1 11 01 01111 011 111 x and y have no separating extension. ε 0111 0

0111 011 11 1

Write the number 53 in binary. (no leading 0's)

110101

Pick the CFG that decides the language { 0n1n | n∈ℕ } ∪ { 1n0n | n∈ℕ }. S → A | B A → 0A1 | ε B → 1B0 | ε S → 0S | S0 | 1S | S1 | ε S → A | B A → 0A0 | ε B → 1B1 | ε S → 0S1 | 1S0 | ε

S → A | B A → 0A1 | ε B → 1B0 | ε

Mark all that apply. ε = ∅ ∅ ∈ {0,1}* ∅ has cardinality 0 ε has length 0 ∅ has length 0 ε has cardinality 0 ε ∈ ∅ ε ∈ {0,1}* ∅ ⊆ {0,1}*

∅ has cardinality 0 ε has length 0 ε ∈ {0,1}* ∅ ⊆ {0,1}*

Mark all of the statements that use the pigeonhole principle. -If I walk up a mountain path starting at the bottom at 8:00am one day, and I walk down the same path starting at the top at 8:00am the next day, there must be a position on the path that I cross at the exact same time both days. This is because, if I consider someone starting at the bottom at 8:00am on the second day and following my exact trajectory up from the day before, while I walk down at the same time, I must cross this person at some point. -My socks are all black, white, or gray. I want to select two socks of the same color, but the room is too dark to see the colors, and if I turn on the light, I will wake up my partner. So I reach into the dresser and grab 4 socks arbitrarily, knowing that two socks are guaranteed to match. -No person has more than 200,000 hairs on their head. (Most have between 90,000 and 150,000.) Sacramento has 495,000 people. Therefore, two people in Sacramento currently have the exact same number of hairs on their head. -Traffic lights at an intersection cannot be green in two orthogonal directions at once. So each intersection has 4 red lights, or 3 red and 1 green light, or 2 red and 2 green lights. Therefore, the total number of red lights in Davis right now is at least the number of green lights. -There are over 1000 computer science students at UC-Davis, but only 366 possible birthdays. Therefore, two students must have the same birthday.

-There are over 1000 computer science students at UC-Davis, but only 366 possible birthdays. Therefore, two students must have the same birthday. -No person has more than 200,000 hairs on their head. (Most have between 90,000 and 150,000.) Sacramento has 495,000 people. Therefore, two people in Sacramento currently have the exact same number of hairs on their head. -My socks are all black, white, or gray. I want to select two socks of the same color, but the room is too dark to see the colors, and if I turn on the light, I will wake up my partner. So I reach into the dresser and grab 4 socks arbitrarily, knowing that two socks are guaranteed to match.

Convert the binary number 11101101 to decimal, with no leading 0's.

237

Suppose sn is the binary expansion of a natural number n. If we append a 1 to the end of sn (near the least significant bit), what number does it represent? 2·n+1 2·n 10·n n+1

2·n+1

Let n be a natural number. What is the number of binary strings of length n? 2·n n n^2 2^n

2ⁿ

What is the extra ability an expression automaton (EA) has compared to a nondeterministic finite automaton (NFA)? An EA can have only a single start state. It can have multiple transitions out of a state labeled with the same symbol or ε. An EA's transitions can be labeled with ε, rather than only single symbols. An EA's transitions can be labeled with arbitrary regular expressions, rather than only single symbols or ε.

An EA's transitions can be labeled with arbitrary regular expressions, rather than only single symbols or ε.

Match each subfield of theoretical computer science to a description of the subject it studies. Automata Theory Computational Complexity Theory Computability Theory Options: What problems can algorithms solve efficiently? What problems can algorithms solve with "optimal" efficiency (constant space and "real time", i.e., time = size of input)? What problems can algorithms solve?

Automata Theory What problems can algorithms solve with "optimal" efficiency (constant space and "real time", i.e., time = size of input)? Computational Complexity Theory What problems can algorithms solve efficiently? Computability Theory What problems can algorithms solve?

Let D be a DFA, let x be a string, and let L be a language. Mark all of the following that are correct usages of the terms (in other words, the statement could be true, with suitable choices for D, x, and L.) D rejects x. D decides L. D decides x. D rejects L. L accepts x.

D rejects x. D decides L.

Consider the CFG G: E → E + T | T T → T x F | F F → (E) | a Mark which of the following are valid derivations for G. E ⇒ T ⇒ T x F ⇒ F x F ⇒ F x (E) ⇒ F x (E + T) ⇒ F x (T + T) ⇒ F x (T + F) ⇒ F x (F + F) ⇒ F x (F + a) ⇒ a x (F + a) ⇒ a x (a + a) E ⇒ E + T ⇒ T + T ⇒ F + T ⇒ F + F ⇒ a + F ⇒ a + F x F ⇒ a + a x F ⇒ a + a x a E ⇒ E + T ⇒ T + T ⇒ T x F + T ⇒ T x F + F ⇒ F x F + F ⇒ F x F + a ⇒ F x a + a ⇒ a x a + a E ⇒ E + T ⇒ T + T ⇒ T x F + T ⇒ T x F + F ⇒ F x F + F ⇒ F x F + a ⇒ F x a + a ⇒ a x a + a ⇒ a x (a + a)

E ⇒ T ⇒ T x F ⇒ F x F ⇒ F x (E) ⇒ F x (E + T) ⇒ F x (T + T) ⇒ F x (T + F) ⇒ F x (F + F) ⇒ F x (F + a) ⇒ a x (F + a) ⇒ a x (a + a) E ⇒ E + T ⇒ T + T ⇒ T x F + T ⇒ T x F + F ⇒ F x F + F ⇒ F x F + a ⇒ F x a + a ⇒ a x a + a

Let M1 = (Q1,Σ,δ1,s1,F1) and M2 = (Q2,Σ,δ2,s2,F2) be two DFAs, and let M = (Q,Σ,δ,s,F) be the DFA obtained by applying the product construction to M1 and M2, such that L(M) = L(M1) ∩ L(M2). Then F = F1 ∪ F2 F = F1 ∩ F2 F = F1 × F2 F = { (q1,q2) | q1 ∈ F1 or q2 ∈ F2 }

F = F1 × F2

Let M1 = (Q1,Σ,δ1,s1,F1) and M2 = (Q2,Σ,δ2,s2,F2) be two DFAs, and let M = (Q,Σ,δ,s,F) be the DFA obtained by applying the product construction to M1 and M2, such that L(M) = L(M1) ∪ L(M2). Then F = F1 × F2 F = F1 ∪ F2 F = F1 ∩ F2 F = { (q1,q2) | q1 ∈ F1 or q2 ∈ F2 }

F = { (q1,q2) | q1 ∈ F1 or q2 ∈ F2 }

The statement "The class of regular languages is closed under the union operation" means that If A and B are regular languages, then A ∪ B is close to being regular. If C is a regular language, then for all languages A and B such that C = A ∪ B, A and B are both regular also. If A and B are regular languages, then A ∪ B is not regular. If A and B are regular languages, then A ∪ B is also regular.

If A and B are regular languages, then A ∪ B is also regular.

Mark all that apply. All regular languages are finite. If A and B are regular languages, then A ∪ B is regular also. If A ∪ B is a regular language, then A and B are regular languages also. All finite languages are regular. If A and B are regular languages, then A ∪ ((B∘A) ∩ A) is regular also. Given two regexs R1 and R2, there is a DFA deciding L(R1) ∩ L(R2). Given an NFA N, there is a regex deciding L(N)*.

If A and B are regular languages, then A ∪ B is regular also. (The product construction can turn a DFA deciding A and a DFA deciding B into a DFA deciding A ∪ B.) All finite languages are regular. (If a language {x1, x2, ..., xk} is finite, then the regex x1 ∪ x2 ∪ ... ∪ xk decides it.) If A and B are regular languages, then A ∪ ((B∘A) ∩ A) is regular also. (The regular languages are closed under concatenation, intersection, union, and complement, so the expressed language is regular also.) Given two regexs R1 and R2, there is a DFA deciding L(R1) ∩ L(R2). (Since L(R1) and L(R2) are both regular, and the regular languages are closed under ∩, then L(R1) ∩ L(R2) is also regular, hence decided by some DFA.) Given an NFA N, there is a regex deciding L(N)*.( (Since L(N) is regular, and the regular languages are closed under *, this means L(N)* is also regular, hence decided by some regex.)

Let G be a grammar where all rules are of one of the following two forms: A → ε or A → bC for terminal b and variable C. Then L(G) is decided by some RRG. L(G) is decided by some regex. L(G) is decided by some DFA. L(G) is decided by some NFA. L(G) is context-free.

L(G) is context-free. since G is a context-free grammar, L(G) is context-free by definition. L(G) is decided by some NFA. since G is a right-regular grammar, L(G) is regular, so decided by some NFA. L(G) is decided by some regex, since G is a right-regular grammar, L(G) is regular, so decided by some regex. L(G) is decided by some RRG. since G is a right-regular grammar, L(G) is decided by it by definition. L(G) is decided by some DFA. since G is a right-regular grammar, L(G) is regular, so decided by some DFA.

Let G be a grammar where all rules are of one of the following three forms: A → ε or A → bC for terminal b and variable C, or A → Cb for terminal b and variable C. Then L(G) is decided by some RRG. L(G) is decided by some regex. L(G) is decided by some DFA. L(G) is decided by some NFA. L(G) is context-free.

L(G) is context-free. since G is a context-free grammar, L(G) is context-free by definition.

Let M=(Q,Σ,δ,s,F) be a DFA with Σ={0,1} and F=Q. Mark all that apply: M accepts all strings in {0,1}*. M decides all languages. M rejects only the empty string ε. M decides {0,1}*. M accepts only the strings 0 and 1.

M accepts all strings in {0,1}*. M decides {0,1}*.

Define the DFA M=(Q, Σ, δ, s, F), where Q={a,b,c}, Σ={0,1}, s=a, F={a,c}, and δ is defined by 0 1 a a b b a c c a b Then M accepts 1, 111, and 11111 and M rejects ε, 0, and 11. M accepts 0, 00, and 111 and M rejects ε, 1, and 11. M accepts ε, 0, and 11111, and M rejects 1, 111, and 00. M accepts ε, 0, and 11 and M rejects 1, 111, and 11111.

M accepts ε, 0, and 11 and M rejects 1, 111, and 11111.

Let M=(Q,Σ,δ,s,F) be a DFA with Σ={0,1} and F=∅. Mark all that apply: M decides the empty language ∅. M accepts only the empty string ε. M rejects all strings in {0,1}*. M accepts only the string 0. M decides no languages.

M decides the empty language ∅. M rejects all strings in {0,1}*.

Let M1 = (Q1,Σ,δ1,s1,F1) and M2 = (Q2,Σ,δ2,s2,F2) be two DFAs, and let M = (Q,Σ,δ,s,F) be the DFA obtained by applying the product construction to M1 and M2, such that L(M) = L(M1) ∪ L(M2). Then Q = Q1 ∩ Q2 Q = Q1 ∪ Q2 Q = Q1 ○ Q2 Q = Q1 × Q2

Q = Q1 × Q2

We let a regular expression R also represent L(R), the language of strings that are that R recognizes. Mark all that apply. For any regular expression R, R∅ = ∅ R ∪ ∅ = ∅ Rε = ε Rε = R R ∪ ε = R R∅ = R R ∪ ∅ = R

R∅ = ∅ Rε = R R ∪ ∅ = R

Define the language B = { 0n1n | n∈ℕ }. Suppose we want to prove B is not regular using the Myhill-Nerode Theorem. We must choose an infinite set of strings S that are all pairwise inequivalent, i.e., they are all in different ∼B-equivalence classes, i.e., all pairs of strings in S have a separating extension. Which of the following choices of S work? S = { 0n1n | n∈ℕ } = { ε, 01, 0011, 000111, 00001111, ... } S = { 1n | n∈ℕ } = { ε, 1, 11, 111, 1111, 11111, ... } S = { 0n | n∈ℕ } = { ε, 0, 00, 000, 0000, 00000, ... } S = { 02n | n∈ℕ } = { ε, 00, 0000, 000000, ... } S = { 0n1 | n∈ℕ+ } = { 01, 001, 0001, 00001, 000001, ... }

S = { 0n | n∈ℕ } = { ε, 0, 00, 000, 0000, 00000, ... } S = { 02n | n∈ℕ } = { ε, 00, 0000, 000000, ... } S = { 0n1 | n∈ℕ+ } = { 01, 001, 0001, 00001, 000001, ... }

Mark all that apply. Recall #b(x) is the number of times symbol b appears in string x. *There is a regular expression that matches a ternary string x exactly when #0(x) + #1(x) = 3. *There is an efficient algorithm that indicates if a graph G has a path visiting each edge exactly once. *There is an algorithm that indicates whether a given multivariable polynomial equation has an integer solution. *There is an efficient algorithm that indicates if a graph G has a path visiting each node exactly once. (assuming P ≠ NP) *There is an algorithm that indicates whether a given multivariable polynomial equation has a real solution. *There is a regular expression that matches a ternary string x exactly when #0(x) − #1(x) = 3.

There is a regular expression that matches a ternary string x exactly when #0(x) + #1(x) = 3. There is an efficient algorithm that indicates if a graph G has a path visiting each edge exactly once. There is an algorithm that indicates whether a given multivariable polynomial equation has a real solution.

Which subfield of computer science is most used in the design of source code parsers for compilers and interpreters? information security NP-completeness deep learning automata theory databases computational biology hardware architecture

automata theory

The regular expression R=a*b(a∪b)*c(a∪b∪c)* decides the subset of {a,b,c}* of strings in which (mark the one description below that describes exactly the strings accepted by R) b and c both appear, and the first b appears before the first c. every appearance of b is followed eventually by a c. the substring bc appears at least one b and at least one c appear.

b and c both appear, and the first b appears before the first c.

Mark all that apply. The regular languages are closed under the operations of intersection union Kleene star complement concatenation

intersection union Kleene star complement concatenation

Suppose we have NFA N with k states. Let N' be the NFA obtained by the NFA star construction. How many states does N have? k+1 k^2 2k k

k+1

Suppose we have NFAs N1 and N2 with k1 and k2 states each, respectively. Let N be the NFA obtained by the NFA concatenation construction. How many states does N have? k1+k2 k1·k2 k1^k2 k2^k1

k1+k2

Suppose we have NFAs N1 and N2 with k1 and k2 states each, respectively. Let N be the NFA obtained by the NFA union construction. How many states does N have? k2^k1 k1^k2 k1·k2 k1+k2+1

k1+k2+1

Let R be a RRG constructed from a DFA D as in the construction given in the notes section entitled "Equivalence of RGs and NFAs". Suppose D has n states, m accept states, and k input alphabet symbols. How many rules does R have? (Note that many rules can be written on one line; for instance A → BC | Dx | ε represents 3 rules. nk + m nm n + m nk + nm

nk + m

If M=(Q,Σ,δ,s,F) is a DFA with n=|Q| and k=|Σ|, then the number of transitions1 M has is number of transitions = number of arrows in its state diagram, where a single arrow counts as more than one if it is labeled with multiple input symbols kⁿ 2ⁿ n^k n·k

n·k

A language L is called DFA-decidable if and only if L is finite. some deterministic finite automaton decides L. L is infinite. L = ∅. L contains all strings over some alphabet.

some deterministic finite automaton decides L.

Let G be the following CFG: R → S | TRX S → aTb | bTa T → XTX | Xc | ε X → c | d Write the terminals of G, in the order they first appear above. (reading the first line left-to-right, then the second line left-to-right, etc.) terminal 1 = terminal 2 = terminal 3 = terminal 4 =

terminal 1 =a terminal 2 =b terminal 3 =c terminal 4 =d

Let L be a regular language. Then there is a RRG that decides L there is a CFG that decides L there is an NFA that decides L. there is a DFA that decides L. there is a regex that decides L.

there is a RRG that decides L there is a CFG that decides L there is an NFA that decides L. there is a DFA that decides L. there is a regex that decides L.

Let G be the following CFG: R → S | TRX S → aTb | bTa T → XTX | Xc | ε X → c | d Write the variables of G, in the order they first appear above. (reading the first line left-to-right, then the second line left-to-right, etc.) variable 1 = variable 2 = variable 3 = variable 4 =

variable 1 =R variable 2 =S variable 3 =T variable 4 =X

Define the language C = { w∈{0,1}* | #(0,w) = #(1,w) }. Let x = 01 and y = 10. Which of the following are separating extensions for x and y? 01 0 1 ε 10 x and y have no separating extension.

x and y have no separating extension.

Suppose an NFA with states {x,y} and input alphabet {0,1} has this transition function: Δ(x,0) = ∅ Δ(x,1) = {y} Δ(x,ε) = {x,y} Δ(y,0) = {y} Δ(y,1) = {x} Δ(y,ε) = ∅ Mark all the transitions that are in the set of transitions of the NFA. y⟶εx y⟶εx x⟶1x x⟶1x x⟶0y x⟶0y y⟶1y y⟶1y x⟶0x x⟶0x x⟶εx x⟶εx y⟶εy y⟶εy y⟶0y y⟶0y y⟶1x y⟶1x x⟶1y x⟶1y y⟶0x y⟶0x x⟶εy

x⟶εx x⟶εy y⟶0y y⟶1x x⟶1y

Pick the correct description of the language decided by the following CFG: S → 0S0 | 1S1 | 0 | 1 | ε { w∈{0,1}* | w=wR }, where wR is the reverse of w. { 0n1n | n∈ℕ } ∪ { 1n0n | n∈ℕ } the language described by the regex (00 ∪ 11)* { 0n | n∈ℕ } ∪ { 1n | n∈ℕ }

{ w∈{0,1}* | w=wR }, where wR is the reverse of w.

Suppose an NFA with input alphabet {0,1} and states {a,b} has this set of transitions: a⟶0b a⟶0b a⟶εb a⟶εb b⟶0b b⟶0b b⟶1a b⟶1a b⟶1b b⟶1b What is the fully-specified transition function Δ? Δ(a,0) = {a,b} Δ(a,1) = ∅ Δ(a,ε) = {b} Δ(b,0) = {a,b} Δ(b,1) = {b} Δ(b,ε) = ∅ Δ(a,0) = {b} Δ(a,ε) = {b} Δ(b,0) = {b} Δ(b,1) = {a} Δ(b,1) = {b} Δ(a,0) = b Δ(a,ε) = b Δ(b,0) = b Δ(b,1) = a Δ(b,1) = b Δ(a,0) = {b} Δ(a,1) = ∅ Δ(a,ε) = {b} Δ(b,0) = {b} Δ(b,1) = {a,b} Δ(b,ε) = ∅

Δ(a,0) = {b} Δ(a,1) = ∅ Δ(a,ε) = {b} Δ(b,0) = {b} Δ(b,1) = {a,b} Δ(b,ε) = ∅

Given an NFA N=(Q,Σ,Δ,s,F), the type of the transition function is Δ:(Q∪{ε})×Σ→P(Q) Δ:Q×(Σ∪{ε})→Q Δ:Q×Σ→Q Δ:Q×(Σ∪{ε})→P(Q)

Δ:Q×(Σ∪{ε})→P(Q)

Writing δ:Q×Σ→Q means the following: δ is a function that, if given inputs called Q and Σ, produces output Q. δ is a function that takes one input from the set Q, and produces two outputs, one from the set Q and one from the set Σ. δ is a predicate from Q×Σ to Q. δ is a function that takes two inputs, one from the set Q and one from the set Σ, and produces an output from the set Q.

δ is a function that takes two inputs, one from the set Q and one from the set Σ, and produces an output from the set Q.


Set pelajaran terkait

continued continued practice exam

View Set

Stage Management - Risk Assessment

View Set

Saunders Adult Health/Pharmacology Hematological and Muscoskeletal

View Set

Database Final - Exam 1 Questions

View Set

Chapter 35: The Agency Relationship

View Set

micro-econ midterm exam practice

View Set

CH. 21 - Nurse as Teacher & Counselor

View Set

Chapter 2: Asset Security (Domain 2)

View Set