As I understand it carts are saved as quotes, even for guests. Logged in users have a customer ID which is stored with the quote, guests do not so their quote has a null customer ID, hence you may find a store has a lot of orphaned/incomplete quotes in the DB. The only way to associate a guest with their cart is by storing the quote ID in their session.
You could extend how long their quote is available to them by storing the quote ID directly in their cookie with a long timeout but this leads to an obvious security breach; anyone could adjust the value in their cookie and view anyone else's cart.
The only safe way is to proceed is to create a table of guest tokens and associate it with quotes (sorry no code this time, there's too much to explain in a low level). The token is the only public part and is set in the cookie. Tokens should be random and long, say 512-bits/64-chars, but not too long because they are included in every HTTP header. Every time a new session is created it might be a returning guest so check for a token and look it up in the table. Take the found quote ID and store that in the session thereby resurrecting the old cart. Quotes with customer IDs don't need to be rescued this way so should be exempt, especially since a logging-out customer doesn't want to see any part of their account remain visible.