Write an algorithm with the following signature: int findPattern (string text, string word) The first parameter is a tex
Posted: Sat Feb 19, 2022 3:23 pm
Write an algorithm with the following signature: int findPattern (string text, string word) The first parameter is a text containing words. The words are separated by one blank character (space). The second parameter contains one word. All words can only contain small letters in the English alphabet (a-z)- z). The same letter cannot occur more than once in word. The task is to find words int the parameter text that contain all the letters in the parameter word. The return value is an integer and can have the following values: 1. There is a word in text, which is identical with word. 2. There is a word in text, which contains the same letters as in word, but in a different order, e.g. word is equal to "som", word in text qual to "mos". 3. There is a word in text, which contains all the letters in word and in the same order, e.g. word is equal to "som" and word in text equal to "storkemor”, or in a different order, e.g.word equal to "som" and word in text equal to "ostemad". If none of the criteria are fulfilled. The return value is 0. More than one criterion can be fulfilled and the criterion with the lowest return value has precedence. That means that if there is an identical word the return value must be 1. If there is not an identical word but one with the same letters, the return value must be 2 etc. The only methods from the String/string-classes you may use are charAt(); length(). comparelo () in Java and at(), length(), compare () in C++. To receive maximum points, the best-case time complexity must be less than O(log N), and the parameter text may only be traversed once.