Couple of footnotes:
As regards a changeover of government in the UK after an election:
For some time preceding an election, the permanent civil servants in each department will have a team working on discreet contacts with the opposition shadow ministers to understand their policy thinking and priorities. Once an election is called, the civil service “goes into purdah” (as it’s called), and though it carries on the back office work and the most routine of public business, it does nothing that could look like working for the government party. However, the team working on understanding the opposition goes through their manifesto and steps up its activity preparing briefings on how the opposition’s ideas might be put into practice, should there be a change of government, so that on the Monday after the election, the new ministers can get the civil servants straight down to work.
As for how appointments are done:
If the result is a clear win for the current government, no change (though I think technically the Queen’s private secretary will make a formal appointment for her to meet and confirm the PM, who will probably take the opportunity to start reshuffling the ministerial team)
If the result is a clear win for the opposition, the Queen’s PS will be on the phone to agree with the PM and the leader of the opposition times to call at the Palace for the formalities. After which, if the election has as usual been on a Thursday, the new PM spends the weekend appointing the new team, so the existing shadow ministers are glued to their phones waiting for the call.
If there’s no clear result, the existing government continues in office until a deal between the parties is done to work out a sustainable arrangement. Only then will the PM inform the Palace as to what the outcome is.
Other countries may have it much more codified, or even written into law. For example, in the Netherlands, where the system almost always requires coalitions, the monarch appoints as “rapporteur” a senior politician, to explore with the parties what combination (s) would work. Where there’s an elected President, s/he may take a more active role along those lines (Italy, I think, but not Germany, where the parties seem to sort it out among themselves). France is sui generis, since it has s US-style executive presidency alongside a PM and ministerial team reflecting the parliament.