Alphabet $A= \{a,b\}$
Define formal languages $L_i$ for conditions $B_i$. You are only allowed to use the following symbols:
$a$ $b$ $\{$ $\}$ $($ $)$ $,$ $^*$ $\cdot{}$ $\cup$
So basically brackets, comma, concatenation and the star.
a) $B_1: |w|$ is odd and $w(0) \neq w(|w|-1)$
b) $B_2: |w| = 0$
c) $B_3: w$ doesn't have $ab$
d) $B_4: w\in L_3 \rightarrow w \in L_2$
My answer:
a) $w$ must have at least 3 symbols and the number of symbols must be odd. So the possibilities in which $a$ and $b$ can show up are: $aaa, aab, aba, baa, bba, bab, abb, bbb$
$L_1= a\cdot \{aa\}^* \cup a\cdot \{ab\}^* \cup a\cdot \{ba\}^* \cup b\cdot \{aa\}^* \cup b\cdot \{ba\}^* \cup b\cdot \{ab\}^* \cup a\cdot \{bb\}^* \cup b\cdot \{bb\}^*$
b) $L_2 = \{\}$
c) $L_3 = \{b\}^* \cdot \{a\}^* \cup \{a\}^* \cup \{b\}^*$
d) $L_4= $
Shouldn't it be then that $L_4 = L_2$ ?
d) No, any word $w$ that isn't in $L_3$ will satisfy $w\in L_3 \Rightarrow w \in L_2$. In fact, $L_4 = \{\textrm{words that have }ab \} \cup \{\epsilon\}$, where $\epsilon$ is the empty word.
Now you get : $$ L_4 = \Big((\{ a \} \cup\{b\})^* \cdot (ab) \cdot (\{ a \} \cup\{b\})^*\Big) \cup \{\}$$
a) Either the first letter is $a$ and the last letter is $b$, or the first letter is $b$ and the last letter is $a$ : $$ L_1 = a\Big(a \cup b \cup a(aa \cup ab \cup ba \cup bb)^* \cup b(aa \cup ab \cup ba \cup bb)^* \Big)b \\ \bigcup b\Big(a \cup b \cup a(aa \cup ab \cup ba \cup bb)^*\cup b(aa \cup ab \cup ba \cup bb)^* \Big)a$$