## Give the complete pseudo code ofthe pattern matching algorithm described above.

Suppose we want to find the first occurrence of a string(Pattern) in a long sting (Text). Let thePattern has k characters P1P2 · · · Pk and Text has N characters A1A2 · · · AN. We can solve thisproblem using hash function. We first compute the hash function H(Pattern) and get a hash valueHp. We then compare this hash value Hp with the hash values formed from strings A1A2 · · · Ak,A2A3 · · · Ak+1, A3A4 · · · Ak+2, and so on until AN-k+1AN-k+2 · · · AN using the same hash function H.If for some substring of Text H(AiAi+1 · · · Ai+k-1) is same as Hp, then we compare the strings(Pattern and AiAi+1 · · · Ai+k-1) character by character to verify the match. We return the position i(in A) if the strings actually do match, and we continue if the match is false. To make this ideaefficient, we need to efficiently compute the hash value of string Ai+1Ai+2 · · · Ai+k using the hashvalue of AiAi+1 · · · Ai+k-1 for 1 <= i<=N-k.Give the hash function H for which we can compute H(Ai+1Ai+2 · · · Ai+k ) using the answer of H(AiAi+1 · · ·Ai+k-1) in O(1). Also show how this computation can be done in O(1). Give the complete pseudo code ofthe pattern matching algorithm described above.

### Compute the information gain of the term “elections” according to Eq. 5.7.

Consider the term “elections” which is present in only 50 documents in a corpus of 1000 documents. Furthermore, assume that the corpus contains 100 documents belonging to the Politics category,….

### Predict the probabilities of categories Cat and Car of Test2 on the toy corpus example in Sect. 5.3.5.2. You can use the multinomial na¨ıve Bayes model with the same level of smoothing as used in the example in the book. Return normalized probabilities that sum to 1 over the two categories. 2.       Na¨ıve Bayes is a generative model in which each class corresponds to one mixture component. Design a fully supervised generalization of the nai¨ıve Bayes model in which each of the k classes contains exactly b > 1 mixture components for a total of b · k mixture components. How would you perform parameter estimation in this model?

1.       Predict the probabilities of categories Cat and Car of Test2 on the toy corpus example in Sect. 5.3.5.2. You can use the multinomial na¨ıve Bayes model with the same….

### What are the possible advantages and disadvantages of using such an approach?

1.       Na¨ıve Bayes is a generative model in which each class corresponds to one mixture component. Design a semi-supervised generalization of the nai¨ıve Bayes model in which each of the….