Avalg homework 2 fall 2003
This homework is due December 9 at 10.15.
It can be delivered to Stefan personally at his office or put in his
mail slot at the department. Do not use the depart mail box.
It can also be given to Stefan in connection with one of the lectures.
Solutions handed in late are not accepted and will not be graded.
Some forms of collaboration are allowed and required. The size of a
group of collaboration should be two people.
All members of the group must be present when the homework is returned.
- Build this data structure for a text t. A solution with worst-case time complexity Omega(n*n), where n is the length of the text, is not good enough. For a full score you will need to find a better algorithm. It's not likely that a quadratic algorithm will meet the time bounds for strings containing 1,000,000 characters. (30p)
- Find the number of substrings of t that match a given string. You should count the number of matching strings. For example, consider the string "abbc" and the pattern "a*b*c". There are two matches, b can match either the first or the second b, even though there is only one string that matches, namely "abbc". (10p)
- Find the length of the longest repeated substring in t. (20p)
- Find the number of substrings of t that match a string which may contain one or more '*'-symbols. A '*' matches any string. For example, consider the string "abbc" and the pattern "a*b*c". There are two matches, b can match either the first or the second b, even though there is only one string that matches, namely "abbc". (30p)
You should give a clear description of the algorithms and an estimate of
the asymptotic worst-case performance for each of the four subtasks.
This is a programming exercise and the same quality standards as in Homework 1 apply. You may assume that the text is stored on file and consists of ASCII characters (excluding '0' and '*'). The program should contain a simple user interface for the queries and the time to execute each command should be reported to the user. The text contains at most 1,000,000 characters. Your goal is to build the suffix array within one minute and the searches should take no more than 10 seconds. You do not know what the text files and queries will look like.
- If there are many elements - e.g. if
*n*is close to 2^*w*, where*w*is the word length - you may sort in linear time. Give an algorithm and discuss how large*n*needs to be. (20p) - If the elements are small you may also sort in linear time. Give an algorithm and discuss how small the elements need to be. (20p)
- You may sort faster if there are many repeated elements. How many distinct elements can you handle and how fast can you sort? (20p)
- The algorithm discussed in class uses large amounts of memory. How much? By doing the radix sorting phase in more than two steps you may reduce the memory requirements while increasing the running time. Explain how to do this and give formulas describing the time-space tradeoff. (20p)
Stefan Nilsson 2003-11-24 |