How are dict and set implemented? What's the lookup complexity and the memory cost?

Technical