Answer
a)
$y=x\ \ $ on $\ \ [0,1]$
$y=-x+2\ \ $ on $\ \ (1,2]$
b)
$y=2\ \ $ on $\ [0,1)$ and $\ [2,3)$
$y=0\ \ $ on $\ [1,2)$ and $\ [3,4]$
Work Step by Step
$a)$ Find the equation of line that goes through the points $\ (0,0)\ \ \mathrm{and}\ \ (1,1)\ $ and the line that goes through $\ (1,1)\ \ \mathrm{and}\ \ (2,0).$ Secondly, write down the domain restrictions.
$y-0=\frac{1-0}{1-0}(x-0)$
$y=x\ \ $ on $\ \ [0,1]$
$y-1=\frac{0-1}{2-1}(x-1)$
$y=-x+2\ \ $ on $\ \ (1,2]$
$b)$ We can see that the upper parts in the graph are represented with the function $\ y=2\ $ and lower parts with the function $\ y=0.$ We just need to apply restrictions on their domains.
$y=2\ \ $ on $\ [0,1)$ and $\ [2,3)$
$y=0\ \ $ on $\ [1,2)$ and $\ [3,4]$