1. A method for representing a state diagram embodying a plurality of signatures to be searched for in an input string of characters, comprising: selecting a goto-failure tree embodying the signatures and including a plurality of branches of sequential states extending from a root node and connected by a number of goto transitions, wherein each non-root state in the goto-failure tree has a failure transition to a corresponding fail state; identifying each sequence of states in the selected goto-failure tree that are connected by a chain of failure transitions; and constructing a failure tree in response to the identifying, wherein the failure tree includes all the states of the goto-failure tree organized in a plurality of depth levels according to a number of failure transitions between each state and the root node.