On a soccer tournament with $n\ge 3$ teams taking part, several matches are played in such a way that among any three teams, some two play a match.
$(a)$ If $n=7$, find the smallest number of matches that must be played.
$(b)$ Find the smallest number of matches in terms of $n$.