  The Wiener polarity index $W_p$, one of the most studied molecular structure
descriptors, was devised by the chemist Harold Wiener for predicting the
boiling points of alkanes. The index $W_p$ for chemical trees (chemical graphs
representing alkanes) is defined as the number of unordered pairs of vertices
at distance 3. A vertex of a chemical tree with the degree at least 3 is called
a branching vertex. A segment of a chemical tree $T$ is a path-subtree $S$
whose terminal vertices have degrees different from 2 in $T$ and every internal
vertex (if exists) of $S$ has degree 2 in $T$. In this paper, the best possible
sharp upper and lower bounds on the Wiener polarity index $W_p$ are derived for
the chemical trees of order $n$ with a given number of branching vertices or
segments, and the corresponding extremal chemical trees are characterized. As a
consequence of the derived results, an open problem concerning the maximal
$W_p$ value of chemical trees with a fixed number of segments or branching
vertices is solved.
