The sentinel trick

from blog purplesyringa's blog, | ↗ original
The sentinel trick underlies a data structure with the following requirements: Read element by index in O ( 1 ) , Write element by index in O ( 1 ) , Replace all elements with a given value in O ( 1 ) . It is not a novel technique by any means, but it doesn’t seem on everyone’s lips, so some of you might find it interesting.