Question

Imagine the following pseudocode

objects[i], 1 <= i <= n 

objects[0] = 0

for i from 1 to n
  if(objects[i] - objects[i-1] > constant)
    do something

I'd like to know if there's a specific name for the assignment objects[0] = 0. I know that when values like these are used to stop loops, they are called sentinel values. In this case, however, I'm using it so that the first object evaluated (objects[1]) will have something to compare against - obviously, objects[0] is not a real object, just sort of a flag. Is it still called a sentinel value? Is there another name for this? Or should I not be doing this at all?

Let me know if I haven't made myself clear and I should try to explain my question in another way.

Was it helpful?

Solution

Cormen et al. writes in Introduction to Algorithms (3rd ed.) on page 238:

A sentinel is a dummy object that allows us to simplify boundary conditions.

This definition is broad enough to account for your usage (e.g. sentinel values of infinity are used in CLRS to simplify the merge routine of mergesort).

OTHER TIPS

I've always called it a "sentinel" whether at the beginning or the end, and haven't yet been fired for that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top