Given a set of large noisy data, a technique which generates line segments and provides an optimal smooth connection of the line segments to form a smoothing function is proposed. In this technique data are recursively subdivided into two subsets, means of the data in each subset are computed and a line segment is defined between the means of two adjacent subsets. An energy function is defined as the sum of variances of all the subsets added with a weighted (by a weighting parameter) sum of squaring the difference of means between two adjacent subsets. Optimal connections of line segments are obtained by the simulated annealing technique. The weighting parameter is introduced in the energy function to express the relative importance of minimizing local variances of data versus the smoothness of connections of line segments. By adjusting the weighting parameter, a second optimization is obtained in the sense that the smoothing function formed by the connected line segments provides the best compromise between the closeness of data to the smoothing function and the optimal smoothness of the function.