When we think about evolution, we think a lot about structure and function. This is because many physical structures of organisms are adaptations—that is, they have evolved over time for a certain function. Note that not all physical traits are adaptations—vestigial structures, for example, are just leftovers from previous ancestors, and have no function at all in modern descendants.
We already talked about homologous structures; recall that structures in two or more organisms are homologous to each other if they were inherited from a common ancestor. Since organisms in different environments may face totally different challenges and demands, their homologous structures sometimes evolve to serve different functions.
For example, the jaws of a Venus flytrap and the spines on a cactus are homologous structures—both are evolutionarily modified leaves. In other words, both the Venus flytrap and cacti inherited leaves from a common ancestor, and over time, those leaves adapted to different environments. The Venus flytrap lives in wet, swampy parts of the southeastern United States, where the soil lacks sufficient nitrogen and phosphorous. But guess what has a lot of nitrogen and phosphorous? Bugs! So, the Venus flytrap has evolved leafy little jaws, which it uses to trap and digest insects and spiders. Yummy.
On the other hand, the great saguaro cactus of the American southwest can grow as big as a tree, and if you've ever had the misfortune of running into one of these guys (or any cactus, for that matter), you know that they can be a tad prickly. Cacti live in hot, dry environments, where having large, soft leaves would lose way too much water by transpiration. Tiny little spiky leaves reduce water loss and protect the cacti from hungry and thirsty desert animals—two extreme kinds of leaves for two extreme environments. This just goes to show how homologous structures (leaves) can evolve to serve two radically different functions in response to different environmental conditions.
On the other hand, sometimes we see cases where different structures in similar environments evolve similar functions—these are called analogous structures. We say structures are analogous in two or more organisms if they did NOT come from a common ancestor, or in other words, if they have evolved independently. The process by which similar structures evolve independently in multiple kinds of organisms is called convergent evolution.
An example of analogous structures is the wings of birds and bats. Many birds and all bats use their wings for flight—superficially, their wings might seem so similar that you're tempted to think they both inherited them from a common ancestor. But wings in bats and birds evolved convergently—that is, each evolved its wings independently. Bats are mammals, and their ancestors, like most other mammals, could not fly. Birds are descended from terrestrial dinosaurs. If we look closely at the wings of bats and birds, we notice some major structural differences: bird wings are made up of the arm and hand bones (humerus, radius, ulna, carpals, metacarpals, and phalanges), and feathers aide in flight.
Bats have the same bones in their wings, but the metacarpals and phalanges (bones homologous to fingers in humans) make up a much greater proportion of the wings than they do in birds. A membrane of skin stretches between these finger bones and gives bat wings their shape. In sum, although the individual bones in bird and bat wings may be homologous because they were present in the last common ancestor. The wings themselves are analogous structures, because they evolved separately in birds and bats. This example shows how similar structures can evolve independently to serve the same function.