Creating a sequence that does not have an increasing or a decreasing sequence of length 3 from a set with 5 elements
You cannot create such a sequence. The general statement is that in any sequence of $n^2+1$ terms, there will be an increasing or decreasing subsequence of $n+1$ terms. Your problem is the $n=2$ version of this.
To prove it, associate each term with an ordered pair. The left element of the pair is the length of the longest increasing subsequence from the left that ends on this element. The right element is the length of the longest decreasing subsequence that starts with this element. For your example, $$\begin {array}{c c c c c} 3&4&2&1&5 \\(1,3)&(2,3)&(1,2)&(1,1)&(3,1) \end {array}$$ You can then read off the length $3$ subsequences: $3,2,1;\ \ 4,2,1;\ \ 3,4,5$ The point is that these ordered pairs are all distinct. For if $a$ is left of $b$ and $a \lt b$, the first element of $b$'s ordered pair will be at least $1$ greater than the first element of $a$'s. If $a \gt b$, the second element of $a$'s pair will be at least one greater than $b$'s. Since there are only $n^2$ pairs with maximum value $n$, there must be at least one pair that includes an $n+1$
I would like to complement the nice answer by Ross Millikan by a somewhat less elementary argument that shows that the lower bound $n^2+1$ for forcing either an increasing or decreasing subsequence of length exceeding $n$ is sharp, namely one can find (many) permutations of $n^2$ that avoid such subsequences.
If one applies the Robinson-Schensted correspondence to a permutation, then corresponding pair of Young tableaux has as number of rows the length of the longest decreasing subsequence of the permutation, while it has as number of columns the length of the longest increasing subsequence. Now the largest Young diagram with no more than $n$ rows and and no more than $n$ columns is the square diagram with $n^2$ unit squares. Therefore one gets the result that a permutation of $n^2+1$ or more has an associate Young diagram with either more than $n$ rows or more than $n$ columns (or both), so it must have either an increasing or decreasing subsequence of length exceeding $n$. But one also gets a method to find precisely the permutations of $n^2$ that do not have such subsequences: take any pair of square standard Young tableaux of size $n\times n$, and apply the Robinson-Schensted correspondence in reverse to find the corresponding permutation. For $n=2$ there are $2$ such Young tableaux; therefore $2^2=4$ among the $24$ permutations of $4$ have the desired property. But this number grows rapidly: for $n=5$ there are $701149020$ square Young tableaux and therefore $701149020^2=491\,609\,948\,246\,960\,400$ permutations of $25$ without increasing or decreasing subsequences of length exceeding$~5$ (but this large number is still a very small fraction of all $25!=15\,511\,210\,043\,330\,985\,984\,000\,000$ permutations of$~25$).
Note also that one can impose separate limits $n,m$ on the length of increasing and decreasing subsequences; one can then go up to permutations of $nm$ without exceeding these limits.
You cannot find such a permutation:
Let $a_1,a_2,a_3,a_4,a_5$ be a permutation of $1,2,3,4,5$.
- If $a_1\not\in\{4,5\}$ and $a_5\not\in\{4,5\}$ then $a_1,4,5$ is an increasing subsequence or $5,4,a_5$ is a decreasing, depending in what order $4,5$ appear in $a_2,a_3,a_4$.
- If $a_1\not\in\{4,5\}$ and $a_5\in\{4,5\}$ then
(i) $a_5=5$: $a_1,4,5$ is an increasing subsequence,
(ii) $a_1=3,a_5=4$: $1,2,4$ is an increasing subsequence or $3,2,1$ decreasing , depending in what order $1,2$ appear in $a_2,a_3,a_4$,
(iii)$a_1\neq3,a_5=4$: $a_1,3,4$ is an increasing subsequence. - If $a_1\in\{4,5\}$ and $a_5\not\in\{4,5\}$ then we proceed as in the previous case.
- If $\{a_1,a_5\}=\{4,5\}$ $2,3,a_5$ is an increasing subsequence or $a_1,3,2$ is a decreasing, depending in what order $2,3$ appear in $a_1,a_2,a_3,a_4,a_5$.