The Nikon D5100 camera body does not have an in-built focus motor.
The G lenses are AF-S lenses which include a focus motor inside the lens - these lenses can be used with entry level camera bodies such as the D3100, D3200, D5xxx series.
AF-S lenses also do not include an aperture ring and will not be compatible with older Film cameras.
The D lenses are older lenses. These lenses would include an aperture ring and would be compatible with older Film cameras.
Few D lenses are AF lenses which do not include an auto-focus motor inside the lens. If auto-focus is a requirement, these lenses require a camera, generally in the mid-to-high-pro-level body range which include a screw-drive focusing motor (auto-focus motor) inside the camera. These lenses will work on the entry level Nikon cameras but focusing will need to be done manually.
Few of the D lenses range also have AF-S. These lenses will be able to auto-focus on the entry level Nikon cameras including the D5100. The 300mm f/4D AF-S is an example of this which is currently available.
The D lenses are also somewhat cheaper compared to the G lenses. However, to use auto-focus on the D lenses with AF, you need to invest more on the higher level camera body - D7000 and above.
If you are currently using the 50mm 1.8D on your D5100 camera, you are probably using manual focus for taking your photographs.
List of Nikon F-mount lenses with integrated autofocus motor - Wiki Link - http://en.wikipedia.org/wiki/List_of_Nikon_compatible_lenses_with_integrated_autofocus-motor