A P-trap and U-bend both prevent sewer gas backflow. P-traps have a curved shape, while U-bends are more angular, serving the same purpose in plumbing systems.