Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

CSE 105 Winter 2023

Homework 1 solutions

Due date: Tuesday, January 17 2023 at 11:59pm

Question 0.  (1 point)

First, set up all the tools required for this class. make sure you are enrolled in the Piazza site for this class.  Confirm you have access to this class via Gradescope https://gradescope.com/ using your ucsd.edu email address. Make sure you are enrolled in the canvas site. This will be the main website for the class.

Make sure you complete the Canvas assignment:

First Day Survey: Prior Knowledge #FinAid

This is important for the university to determine the commencement of academic work for each student in the class for the purposes of Financial Aid. Please ll it out.

Question 1.  (15 points) Let A = {aa, bb, ab}, B = {a, b}, C = {ab, abab, ababab}.  For each set, write out each of its elements.

a.  (A u B u C)

Solution:

{aa, bb, ab, a, b, ab, abab, ababab}

b.  (A n C) × (B u C)

Solution:

{(ab, a), (ab, b), (ab, ab), (ab, abab), (ab, ababab)}

c.  A o C

Solution:

{aaab, aaabab, aaababab, bbab, bbabab, bbababab, abababab} d. p(C) (the power set of C)

Solution:

{0, {ab}, {abab}, {ababab}, {ab, abab}, {ab, ababab}, {abab, ababab}, {ab, abab, ababab}}

e.  (B o B) × B

Solution:

{(aa, a), (ab, a), (ba, a), (bb, a), (aa, b), (ab, b), (ba, b), (bb, b)}

Question 2.  (14 points) True/False State whether each statement is true or false and justify with one or two sentences.  For example, if the statement is true and follows from definition(s), write out the relevant definitions and explain how they apply.

a.  A u B = A n B

Solution: True, this is called DeMorgan’s law.

b.  There exists a nite set A that has the same number of elements as its own power set p(A). Solution:  False, it can be shown that if A is nite and |A| = n, then |p(A)| = 2n  and n < 2n  for all integers n.

c.  {0} u {0, 1} = {0, 1}.

Solution: False: the correct set would be:  {0, 0, 1}.

d.  0 e {0, 1}

Solution: False, the only elements of {0, 1} are 0 and 1, not the empty set.

e.  {0, 1} n {00, 11} = {0}

Solution: False, the correct set should be 0.

f.  0 C {0, 1}.

Solution: True, the empty set is a subset of any set.

g.  0 is a language.

Solution:  True, the empty set can be considered to be the empty set of strings and so it is a set of strings.

Question 3.  (23 points) CSE 105 is a fairly proof heavy class. The goal of this problem is to help refresh your memory on different proof techniques: proof by induction, closure proofs and set equality proofs.

For each part of this question, complete the proofs by lling in the blanks.

Note:  there  may  be  alternate  correct proofs  to  each  of these  claims .   The point  of this  question  is  to practice certain proof strategies .

a.  (6 points)

Denition: The reverse of a string u, denoted uR , is defined recursively as follows:

(1) εR  = ε (Note that ε is the empty string.)

(2)  For any character a, and any string w, then (wa)R  = awR .

This denition, in words, is on page  14 .

Claim:  (uv)R  = vR uR  for any strings u and v .

Proof: By structural induction on v .

Base case: v = ε . Let u be any string.

(uε)R  =   uR  = εuR     = εR uR

Induction step:  Let v be an arbitrary string.  Assume that for all strings u, (uv)R  = vR uR . We need to show that, for each character a and all strings u, (u va)R  = (va)R uR .

By the recursive denition of reverse:  (u va)R  =  a(uv)R  .

By the inductive hypothesis:  (uv)R  =  vR uR  .

Also, by the recursive definition of reverse:  (va)R  =  avR  .

Thus,

(u va)R      ()       a(uv)R

()        a /vR uR= (avR )uR

()      (va)R uR .                 

b.  Prove that if A C R is closed under multiplication and B C R is closed under multiplication then

A n B is closed under multiplication and A n B is not necessarily closed under multiplication.

A n B is closed under multiplication.

Let x, y be elements of A n B .  (Show that xy e A n B .

Solution:

Suppose that x, y are elements of A n B . Then xy is an element of A because A is closed under multiplication.  xy is an element of B because B is closed under multiplication.  So since xy is an element of both A and B , xy is an element of A n B .


A u B not necessarily closed under multiplication.

Find a counterexample of a pair of subsets of the real numbers, A and B each closed under multiplication but their union is not closed under multiplication.

Solution:

Consider the sets A = {3k + 1 | k e Z} and B = {4k + 1 | k e Z}.  Then A is closed under multiplication and B is closed under multiplication but A u B is not closed under multiplication because, for example, 7 e A, 5 e B but 5 * 7 = 35 is not in A and 35 is not in B .

c.  Consider the sets:

A = {w e {0, 1}* | 10 is a substring of w}

B = {0n 1m |n, m > 0}

Fill in the blanks to show that A = B .                      

In order to prove set equality, we must prove A C B and B C A.

  A C B .

Suppose that w e  A .  Then w does not have any 2-element substrings of the form 10. This means that there can never  be a  1  before a  0  in w . So all 0’s must come before all 1’s and so w has the form  0n 1m   and w e B .

Suppose that w  e   B .   Then w must have the form 0n 1m .   The only possible 2-element substrings of w are:   00 ,  01          .  Therefore   10  is not a substring of w and so w e A.


Question 4.  (14 points) Consider the alphabet Σ = {c, d}. Match each regular expression with the language

it represents.  If the regular expression does not match any language in the list provided, write the language the regular expression does represent.  For each language, assume the alphabet is Σ = {c, d}.  Remember to justify your answers.  (Hint:  since there are only two letters in the alphabet, if you avoid cc and dd then that means that the string must alternate between the letters c and d.)

(1)  dc* d

(a)  {w e Σ*   | w starts and ends with d and avoids cc and dd}

(2)  (cc)* d(cc)*

(b)  {w e Σ*   | w starts and ends with c and has exacly one d.}

(3)  cc* dcc*

(c)  {dcn d  |  n > 0}

(4)  (c n ε)(dc)* (d n ε)

(d)  {w e Σ*   |  |w| > 2 and w begins and ends with d}

(5)  (dc)* d(cd)*

(e)  {c2ndc2m    |  n > 0 and m > 0}

(6)  cΣ* n dΣ*

(f)  {w e Σ*    |  |w| > 1}

(7)  d(c n d)* d

(g)  {w e Σ*    |  w has an even number of cs}

(h)  {c2ndc2n    |  n > 0}

(i)  {w e Σ*  | w avoids cc and dd}

Solution:

(1)  (c) it is all the strings with a d followed by any amount of c’s followed by a d.

(2)  (e) It is the set of strings with an even number of c’s then a d then another even number of c’s (possibly different number of c’s than the rst stretch)

(3)  (b) Just like it says in the set builder, there must be a d and it must start and end in a c.

(4)  (i) This set includes any string that alternates between the characters c and d and so it will never have cc or dd.

(5)  (a) Essentially it is d and c alternating and it starts and ends in d.  Alternating means that it avoids cc and dd.

(6)  (f) All strings with 1 or more symbols.

(7)  (d) The regular expression starts with a d and ends with a d, which guarantees all strings have length 2 and start and end with a d.