For a graph G, the Hosoya index and the Merrifield Simmons index are defined as the total number of its matchings and the total number of its independent sets, respectively. In this paper, we characterize the structure of those graphs that minimize the Merrifield-Simmons index and those that maximize the Hosoya index in two classes of simple connected graphs with n vertices: graphs with fixed matching number and graphs with fixed connect...