The linearization problem is the problem of finding the coefficients C"k(m,n) in the expansion of the product P"n(x)Q"m(x) of two polynomial systems in terms of a third sequence of polynomials R"k(x),P"n(x)Q"m(x)=@?k=0n+mC"k(m,n)R"k(x). The polynomials P"n, Q"m and R"k may belong to three different polynomial families. In the case P=Q=R, we get the (standard) linearization or Clebsch-Gordan-type problem. If Q"m(x)=1, we are faced with the so-called connection problem. In this paper, we compute explicitly, in a more general setting and using an algorithmic approach, the connection and linearization coefficients of the Askey-Wilson orthogonal polynomial families. We find our results by an application of computer algebra. The major algorithmic tool for our development is a refined version of q-Petkovsek@?s algorithm published by Horn (2008), Horn et al. (2012) and implemented in Maple by Sprenger (2009), Sprenger and Koepf (2012) (in his package qFPS.mpl) which finds the q-hypergeometric term solutions of q-holonomic recurrence equations. The major ingredients which make this application non-trivial are*the use of appropriate operators D"x and S"x; *the use of an appropriate basis B"n(a,x) for these operators; *and a suitable characterization of the classical orthogonal polynomials on a non-uniform lattice which was developed very recently (Foupouagnigni et al., 2011). Without this preprocessing the relevant recurrence equations are not accessible, and without the mentioned algorithm the solutions of these recurrence equations are out of reach. Furthermore, we present an algorithm to deduce the inversion coefficients for the basis B"n(a,x) in terms of the Askey-Wilson polynomials. Our results generalize and extend known results, and they can be used to deduce the connection and linearization coefficients for any family of classical orthogonal polynomial (including very classical orthogonal polynomials and classical orthogonal polynomials on non-uniform lattices), using the fact that from the Askey-Wilson polynomials, one can deduce, by specialization and/or by limiting processes, any other family of classical orthogonal polynomials. As illustration, we give explicitly the connection coefficients of the continuous q-Hahn, q-Racah and Wilson polynomials.