codeintuition-logo

Understanding the sequence validation pattern


There are some problems where we need to operate on interrelated data. An example of this could be a pair of events that denote the start and end of an interval. Another example could be opening and closing brackets that denote the start and end of a context. When dealing with a sequence of such events, a set of rules governs the validity of the sequence, which is generally defined by the problem. In most cases, to validate the sequence, we must move through the sequence, keeping track of several events and getting them in the order of most to least recent when needed.

Loading Image

A sequence of interrelated events.

The sequence validation technique uses the LIFO property of a stack to solve such problems by storing relevant events in the stack, which maintains the most to least recent order.

Liking the course? Check our discounted plans to continue learning.