An interval

$I(u,v)$ in a graph

$G$, where

$u$,

$v$ are vertices, is the set of all vertices

$w$ of

$G$ for which the equality

$d(u,w)+d(w,v)=d(u,v)$ holds, where

$d$ denotes the distance. If for any three vertices

$u$,

$v$,

$w$ of

$G$ the intersection

$I(u,v)\cap I(v,w)\cap I(w,u)$ consists of one vertex only, then

$G$ is called a median graph. A profile of length

$p$ on a graph

$G$ is a finite sequence

${v}_{1},{v}_{2},\cdots ,{v}_{p}$ of vertices of

$G$; its median is a vertex

$x$ of

$G$ for which

${\sum}_{i=1}^{p}d(x,{v}_{i})$ is minimal. The set of all medians of a profile

$\pi $ is the median set

$M\left(\pi \right)$. In the paper a strategy for finding

$M\left(\pi \right)$ for a given profile

$\pi $ is described; it is called the majority strategy. It begins in a vertex of

$G$ and consists of certain successive moves from one vertex to another along an edge. It is proved that the majority strategy produces the median set

$M\left(\pi \right)$ for each profile

$\pi $ of

$G$, independently of the initial position, if and only if

$G$ is a median graph.