Water alarms could be ultrasonic, magnetic, float and even electronic to name a few. A float won't help a flooded basement, but could help a water storage tank. A huge tank might use ultrasonics (distance measuring). Magnetic might be used when there are a few levels that need to be detected, say 1/2, 3/4 and full. A pump might turn on at 1/2 and turn on when full.
A one of a kind alarm is an aspirin sitting under a microswitch with the aspirin on the floor. When the aspirin disolves, the alarm goes off.
Electronic alarms are used for a variety of applications in the home. Search for "Water Cop". A water heater leak, a washer leak and a common one for people who have HVAC systems in their attic is to detect water in the overflow pan. Water in the overflow pan will result in the AC not working. If the switch failed, one would have water on the bedroom ceiling. Sump pump failure is another application.
I installed a simple wireless alarm which monitors the level in a french drain in the basement. If that sounds I have to use a wet vac to remove the water before it gets in the basement. I also placed an alarm on a window sill that has a towel on it. If water gets in the window well, the alarm sounds and I have to turn on a bildge pump in the well. The events occurred 2x in one year within 5 weeks.
I've since made improvements in drainage and I should not need it anymore. The improvements work, but are not complete yet.
Electronic level detectors use the conductivity of water. An AC voltage is used to avoid plating of one of the electrodes. dirty water conducts electricity. Pure water doesn't conduct very well.