How do we know which kinds of dinosaurs are most closely related?

Understanding questions of dinosaur behavior and biology depends on a firm understanding of their evolutionary relationships. To reconstruct the evolutionary relationships between different groups of dinosaurs, one must carefully study and analyze the anatomy, essentially searching for characteristics that are shared among different kinds of dinosaurs. These characteristics are then interpreted to have been present in the common ancestor and inherited by its descendants. This analysis produces a branching diagram, called a cladogram, on which different kinds of dinosaurs are shown at the endpoints of the branches.