Every person has at one point or other searched for a sword to fall on because he met a young lady a second time and wasn’t sure whether or not to hug her, or shake hands, or what the hell he does, and therefore had an awkward exchange. Unfortunately I can’t fix that problem, but there are some ways to make greeting people easier.
The simplest way to alleviate awkwardity is to follow what the person initiating does. As for who initiates, the determination is by rank and gender. Aside from very high rank, it is always appropriate for an adult woman to initiate a greeting. It is generally appropriate for an adult male to initiate a handshake with another adult male, or a lower ranking adult female. For instance, if a male interviews a female for a job, it is perfectly acceptable for either to extend a hand to the other. In a social setting it is generally a woman’s prerogative to whom she extends her hand. It is worth noting that people like heads of state, or royalty should not be addressed until they initiate contact. It may seem rude to us, but if you were prince William, and you had over 1,000 people at a garden party (all to see you), it would be the only way to maintain sanity.
When one remembers who’s prerogative it is to extend a hand, the rest is simple. Men shake hands with each other unless they are friends. Women set the pace on whether they shake hands, hug, or anything else.
Assuming an able body, a man should always stand to greet someone, and a woman should stand for someone of sufficient rank, or in a business setting, but may remain seated otherwise. More on that here.