This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: CS 373: Combinatorial Algorithms, Spring 2001 http://www-courses.cs.uiuc.edu/~cs373 Homework 5 (due Tue. Apr. 17, 2001 at 11:59 pm) Name: Net ID: Alias: U 3 / 4 1 Name: Net ID: Alias: U 3 / 4 1 Name: Net ID: Alias: U 3 / 4 1 Neatly print your name(s), NetID(s), and the alias(es) you used for Homework 0 in the boxes above. Please also tell us whether you are an undergraduate, 3/4-unit grad student, or 1-unit grad student by circling U, 3 / 4 , or 1, respectively. Staple this sheet to the top of your homework. RequiredProblems 1. Prove that finding the second smallest of n elements takes EXACTLY n + ⌈ lg n ⌉ − 2 com- parisons in the worst case. Prove for both upper and lower bounds. Hint: find the (first) smallest using an elimination tournament. 2. Fibonacci strings are defined as follows: F 1 = “b” , F 2 = “a” , and F n = F n- 1 F n- 2 , ( n > 2) where the recursive rule uses concatenation of strings, so F 3 is “ab”, F 4 is “aba”. Note that the length of F n is the n th Fibonacci number. (a) Prove that in any Fibonacci string there are no two b’s adjacent and no three a’s. (b) Give the unoptimized and optimized ‘prefix’ (fail) function for F 7 . (c) Prove that, in searching for the Fibonacci string F k , the unoptimized KMP algorithm can shift ⌈ k/ 2 ⌉ times in a row trying to match the last character of the pattern. In other words, prove that there is a chain of failure links m → fail [ m ] → fail [ fail [ m ]] → ... of length ⌈ k/ 2 ⌉ , and find an example text T that would cause KMP to traverse this entire chain at a single text position. CS 373 Homework 5 (due 4/17/01)...
View Full Document
- Spring '09
- Graph Theory, Analysis of algorithms, Fibonacci number, String searching algorithm, lower bounds, Knuth–Morris–Pratt algorithm