Given a set of string(of max length 5) and a text you have to find the minimum span within the text where you can find all the strings of the set(in any order)?
-
eg: if set has:{question answer credit} Text is : Credits make content you care about on Quora more prominent. This prominence can help questions get answered, or get more attention for answers and posts. You'll spend credits to ask someone to answer or promote content. You'll earn credits when people vote up your answers or follow your questions. Solution will be starting and ending index of the bold part
-
Answer:
This is text analysis problem , assume u can use best searching algorithm and suitable data structure , if have set of n elements then you must 2^n subsets e.g power set, so now you basically needs to rank the subsets with strong matching keywords to at higher rank then partially matching keywords and then single word matching keywords , i believe in that way answer will get more attention rather then just showing the them in order they appear in text. This just an improvement over i think what you are looking for.
Shashank Mani Narayan at Quora Visit the source
Other answers
You first need to find the positions at which each string s belonging to the set S of the strings (given to you). If one of the strings does not appear in the text at all, then your answer is 0 (clearly you do not have a span of the text which contains all the strings of the set S). Once you have all the positions of the strings (present in S), the problem reduces to finding the minimum span in the sequence of these positions that contains all the strings. The algorithm can be something like this. 1. Construct a suffix trie ST(T) of the text T (can be done in http://en.wikipedia.org/wiki/Ukkonen%27s_algorithm). 2. For every string s in S, enumerate the string s (with the first string being numbered 0, the second numbered 1, and so on) and check if the string is present in ST(T). If not there, then the answer is 0 and terminate the program. Else get the list of positions of the string s in T (can be stored in the suffix tree ST(T)). This can be done in O(|S|) time. 3. Now that you have the positions of each string i (i ranges from 0 to |S|-1) in the form of a set SiSiS_i of pairs of the form (position, i), you can sort the set S` of the union of SiSiS_i for every i ranging from 0 to |S|-1, on the basis of the position number. This can be done O(|S|log|S|log|S| log|S|) time. 4. Now you can find the minimum span in this sorted sequence which has all the strings. Notes - 1. O(n) - http://en.wikipedia.org/wiki/Big_O_notation 2. If S is a set, then |S| is the number of elements of the set. 3. If T is a string/text, then |T| is the length of the string/text. 4. In the above answer, a. S - is the set of strings given to us. b. T - is the text given to us. c. ST(T) - suffix tree of T. d. SiSiS_i - is the set of positions of string i (representing sisis_i in the set S) in the text T. The elements of this set are stored in the form of the pair (position, i). e. S` - is the union of SiSiS_i for every i ranging from 0 to |S|-1.
Prajwal A N
Related Q & A:
- Where I can find a cheap hostel in Paris?Best solution by Yahoo! Answers
- Does anybody know where i can find a place in Edmond, Oklahoma that makes bagels in the morning?Best solution by Yahoo! Answers
- Do you know a websites where I can find medieval castle floor plans?Best solution by medievalcastles.stormthecastle.com
- Does anyone know where I can find a Blackberry Bold?Best solution by us.blackberry.com
- Where is a website where I can find demographic data. For the US?Best solution by sba.gov
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.