We define a beehive of order $n$ as follows:

a beehive of order 1 is one hexagon

To construct a beehive of order $n$, take a beehive of order $n-1$ and draw a layer of hexagons in the exterior of these hexagons. See diagram for examples of $n=2,3$

Initially some hexagons are infected by a virus. If a hexagon has been infected, it will always be infected. Otherwise, it will be infected if at least 5 out of the 6 neighbours are infected.

Let $f(n)$ be the minimum number of infected hexagons in the beginning so that after a finite time, all hexagons become infected. Find $f(n)$. 
1. **Define the problem and initial conditions:**
   - A beehive of order \( n \) is constructed by taking a beehive of order \( n-1 \) and adding a layer of hexagons around it.
   - Initially, some hexagons are infected by a virus. If a hexagon has been infected, it will always be infected. Otherwise, it will be infected if at least 5 out of its 6 neighbors are infected.
   - We need to find the minimum number of initially infected hexagons, \( f(n) \), such that eventually all hexagons in the beehive of order \( n \) become infected.

2. **Graph theory interpretation:**
   - Represent each hexagon as a vertex in a graph.
   - Two vertices are connected by an edge if and only if the corresponding hexagons share an edge.
   - The induced subgraph of initially non-infected vertices must be acyclic (i.e., a forest) and must be within the inner beehive of order \( n-1 \).

3. **Counting the perimeter of the forest \( T \):**
   - Let \( T \) be the number of vertices in the forest of non-infected vertices.
   - Each vertex in \( T \) has 6 segments in the perimeter. A segment adjacent to two vertices in \( T \) should be counted 0 times, but it is counted 6 times, and there are \( E(T) \) of these.
   - Thus, the perimeter is at least \( 6|T| - 2E(T) \ge 4|T| + 2 \) since \( E(T) \le T - 1 \).

4. **Considering the vertices not in the forest:**
   - The set of vertices not in the forest is connected.
   - Assume not. Then we can partition the vertices into \( A \sqcup B \) where for all \( a \in A, b \in B \), \( ab \) are not adjacent.
   - All vertices on the outer shell must be in one side, say \( A \). Then for each edge on the perimeter of \( B \), the other vertex sharing that edge must be in the forest. This implies that the forest has a cycle, which is a contradiction.

5. **Infection process and perimeter calculation:**
   - Initially, the perimeter is \( 3 \cdot 6 + 2 \cdot 6 \cdot (n-2) \).
   - The first infection increases the perimeter by at most 2, and all other infections increase the perimeter by at most 4.
   - Thus, we have:
     \[
     4|T| + 2 \le N \le 18 + 12(n-3) + 4(3(n-1)(n-2) + 1 - |T|) - 2
     \]
     Simplifying this:
     \[
     4|T| + 1 \le 9 + 6(n-3) + 2(3(n-1)(n-2) + 1) - 1
     \]
     \[
     2|T| \le 3 + 3(n-3) + (3(n-1)(n-2) + 1)
     \]
     \[
     2|T| \le 3n^2 - 6n + 1 = 3(n-1)^2 - 2
     \]
     \[
     |T| \le \left\lfloor \frac{3}{2} (n-1)^2 - 1 \right\rfloor
     \]

6. **Final calculation for \( f(n) \):**
   - The minimum number of initially infected hexagons is given by:
     \[
     f(n) = 3n^2 - 3n + 1 - |T|
     \]
     Substituting the upper bound for \( |T| \):
     \[
     f(n) = 3n^2 - 3n + 1 - \left\lfloor \frac{3}{2} (n-1)^2 - 1 \right\rfloor
     \]
     Simplifying further:
     \[
     f(n) = 3n^2 - \left\lfloor \frac{3}{2} n^2 + \frac{3}{2} \right\rfloor
     \]

The final answer is \( \boxed{ f(n) = 3n^2 - \left\lfloor \frac{3}{2} n^2 + \frac{3}{2} \right\rfloor } \)