
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

(a) Explain how to perform the operation find(x) in time O(log k), where k is the index of the cell containing x (that is A[k] = x). If k ā Ī(n), then a standard binary search would do, but think what to do if k is much smaller than n. Try first narrowing the search to a section of the array that definitely contains x. You should not use any other data structures. (b) Improve your find(x) operation so that it takes O(log min{k, n ā k}) time.
(a) Assuming that the alphabet size for both the pattern and text is binary (i.e. the only charac- ters are a and b), give an efficient algorithm to solve this problem. You should present your solution in pseudocode and also explain clearly how it works. You may assume a function count(c, s) that will return the number of occurrences of character c in string s in linear time. (b) Give the time complexity of your histogram pattern matching algorithm and explain briefly why it is so. (c) Now consider strings over non-binary alphabets. I.e. the characters in the string are no longer limited to a and b only. Give a detailed description of an efficient algorithm to solve this new problem and derive its time complexity. Explain clearly how your algorithm works and what effect the alphabet size (usually denoted |Ī£|) has, if any, on the overall running time.