Let G=(V(G),E(G)) be a molecular graph, where V(G) and E(G) are the
sets of vertices (atoms) and edges (bonds). A topological index of a molecular
graph is a numerical quantity which helps to predict the chemical/physical
properties of the molecules. The Wiener, Wiener polarity and the terminal
Wiener indices are the distance based topological indices. In this paper, we
described a linear time algorithm {\bf(LTA)} that computes the Wiener index for
acyclic graphs and extended this algorithm for unicyclic graphs. The same
algorithms are modified to compute the terminal Wiener index and the Wiener
polarity index. All these algorithms compute the indices in time O(n)