Optimal Search Algorithms For Structured Problems In Natural Language Processing