Solution:

A switch statement is compiled as an "array" of jumps or jump target addresses, one per case of the switch, and a master jump which jumps to one of these addresses based on an address computation. The linear addressing principle is thus used. So the overall time taken for a switch statement is O(1), whereas for a sequence of N if statements it is O(N). This is described fully in the notes on Stored Program Computing.

If the case values are sparsely distributed within a large range, then a lot of space can be wasted in storing the array of addresses or jumps. In this case hashing can be used to store the addresses. With hashing, one uses the switched-upon value to find a bucket, then does a (hopefully short) series of if statements for a given bucket. Finding the bucket is O(1) using the hash function, while doing the tests is a small constant or O(1) if the addresses are evenly distributed.