Ad

# Can You Find All Substrings Of A String In Faster Than O(N^2) Time If Your Constrained About What Sub Strings Your Looking For?

According this answer (Find all possible substring in fastest way). The fastest way to find all possible substrings of a String is `O(N^2)`

. However, is this still true if let's say I have a list of words, and I wan't to see if a certain string x has substrings that are in that list of words. For instance, would creating a trie of the list of words, allow me to optimally ignore certain substrings. Thus making the run time better?

Ad

## Answer

Yes, that is what string searching algorithms are for.

Ad

source: stackoverflow.com

## Related Questions

- → (Javascript) Take Three Integers From User to Display Sum, Average, Product, Smallest, and Largest Number
- → What is the best way in JavaScript to trim down the properties of an object?
- → How to extend Laravel's bcrypt method
- → Most efficient method to check for range of numbers within number without duplicates
- → What is the best way for me to retrieve this information in a sorted manner?
- → React Page recommends keeping logic at a high level
- → Unexpected undefined Value in JS Script
- → javascript find symmetric difference
- → Does React always check the whole tree?
- → How to use a recursive filter all single JSON data?
- → How is document.querySelector implemented?
- → Algorithm to determine correct character ['╦', '╣', '╠', '╩', '╬'] for intersections in grid
- → Optimal compression for a large base 10 number contained in a string

Ad