All of the opinion polls are pointing towards another hung parliament in Thursday's General Election. So what happens next if the result is not decisive? Don't panic the British system of government is designed to cope with uncertainty.
How is the Prime Minister appointed?
A prime minister remains in office until he informs the Queen that he is resigning, usually because his party has been defeated in an election. The Queen then summons an alternative PM - generally the leader of the main opposition party - to ask him to form a government. This person would normally accept, and the Court Circular would record that "the Prime Minister Kissed Hands on Appointment".
In circumstances of exceptional uncertainty, the potential PM can accept an "exploratory commission" and return after a few days to inform the monarch whether he can form a viable government. This occurred in 1963, when Harold Macmillan stepped down due to ill health and it was not immediately clear whether senior Conservatives would accept Lord Home as his successor.
This procedure means that, in a hung parliament, a PM can remain in office for some time after the votes have been counted even if he has fewer MPs than his main rival - as Gordon Brown did for five days in 2010.
So how would David Cameron decide whether to stay or resign?
Mr Cameron would have to judge whether he had any prospect of forming a government which would command the confidence of the new House of Commons in a vote. If any single party has more than half of MPs, this is a simple calculation. In a hung Parliament, the PM would have to establish whether he can form a coalition - or make another less formal arrangement - with one or more smaller parties which would allow him to survive a confidence vote.
How could a coalition be formed?
Parties will put out feelers as soon as results come in and the shape of the new House of Commons becomes clear. In 2010, Mr Cameron offered a "big, open and comprehensive" deal with the Liberal Democrats within hours of the results, sparking five days of meetings between negotiating teams from the three main parties. This time around, the process may well take longer, because more than three parties are likely to be involved and it is entirely possible that no plausible combination of two parties would be able to deliver an overall majority.
What kind of coalitions are possible?
The Liberal Democrats have made clear that - as in 2010 - they will speak first to the party with the most MPs. Nick Clegg says his party is open to coalition with either Labour or the Tories, but will not join a coalition involving either Ukip or the Scottish National Party. Labour has ruled out a coalition with the SNP. Ukip has said it will only support a government which offers a swift referendum on the UK's membership of the European Union, which effectively rules out a deal with Labour. The SNP, Plaid Cymru and the Greens all say they would use their votes to block a Conservative government. The Democratic Unionist Party has said it could make a deal with either the Tories or Labour, though it is not seeking cabinet posts.
This complex arrangement suggests that only a few coalition combinations - Tory/Lib Dem, Labour/Lib Dem or a Labour link-up with smaller parties like the Greens, Plaid or the SDLP - are likely to be on the table. There has been some talk of a "grand coalition" between the Tories and Labour, of the kind seen in some continental countries like Germany, but it is difficult to imagine either of the big parties stomaching such an arrangement at present.
What about a 'confidence and supply' deal?
This would be an agreement short of a formal coalition, under which one or more smaller parties would undertake - in return for certain concessions - not to defeat a minority administration on a vote of no confidence or a "supply" vote on its budget. This would provide some stability and allow one of the larger parties to try to get its agenda through without offering ministerial posts to smaller groupings.
Are those the only options?
No. A minority administration could attempt to govern alone without a formal deal, seeking support from other parties on a vote-by-vote basis. This would be the least stable option and would limit the amount of legislation the government could pass. The most plausible current scenario under which this might happen would be a Miliband government which hoped to rely on support from the SNP and other left-of-centre parties in key votes without striking a deal.
Would a government led by a party which finished second be legitimate?
This is a fraught political question. Under the UK's unwritten constitution, the only requirement is for a Prime Minister to command the confidence of the Commons. However, any minority administration could potentially face public hostility, and its legitimacy would certainly be challenged by political rivals.
Is there a deadline for a government to be formed?
Parliament returns on May 18 for MPs to be sworn in and a Speaker elected, but the real deadline is the State Opening of Parliament on May 27, when the Queen's Speech will set out the agenda for the new government. Traditionally, defeat in a Queen's Speech debate would be taken as a matter of confidence and force the PM's resignation. But the Fixed Term Parliaments Act passed by the coalition in 2011 requires a motion on the specific wording "That this House has no confidence in Her Majesty's Government". It is not clear whether this could be tabled as an amendment during debate on the Speech.
If Mr Cameron decided to try to get a Queen's Speech through the House, but was defeated in a confidence vote, Ed Miliband would then have 14 days to obtain a vote of confidence in a government led by him. If this failed, it would trigger another election, probably in July.
Is that the only way a new election can be called?
No. Another option would be for a two-thirds majority in the House of Commons to vote for an early election. In practice, this is only likely to happen if both Conservatives and Labour support it. Harold Wilson did not face this constraint and was able to call a second election after eight months to move from a minority to a wafer-thin majority in 1974. If a prime minister sought to do so again, it is quite possible the main opposition party would block it, in order to deny him the opportunity to improve his position.