hw1-s10-soln

hw1-s10-soln - CS 4102, Algorithms, HW1, Spring 2010...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CS 4102, Algorithms, HW1, Spring 2010 Problem 22: Prove 2 n = O( n !). We will prove this by induction by showing that for n 4, 2 n n ! or n ! 2 n 1 . Basis Step: Show that for n = 4, n ! 2 n = 4! 2 4 = 24 16 1 . Inductive Step: The induction hypothesis is that for k > 4, assume k ! 2 k 1 . Now show that: ( k + 1)! 2 k + 1 1 . ( k + 1)! 2 k + 1 = ( k + 1) k ! 2 × 2 k = ( k + 1) 2 C , where C = k ! 2 k 1 from the inductive hypothesis. Also, k + 1 2 1 for all values of k > 4. Therefore ( k + 1)! 2 k + 1 is the product of two values 1 , and thus this product must be 1 . Therefore we have shown what we wanted: ( k + 1)! 2 k + 1 1 . Conclusion: We’ve shown that for n 4, 2 n n ! which satisfies the definition of O(f(n)) and proves that 2 n = O( n !).
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Problem B2 Here are three possible solutions. There may be more! Solution #1: For each word w in the dictionary: calculate the set of permutations for w for each permutation p of w: lookup(p) in the dictionary if found, add p to the set of w's anagrams end end The outer loop goes around n times. If each word has length m, there are m! permutations. So there will be (n)(m!) look-ups in the dictionary. If the dictionary uses a hash-table or some kind of index where look-ups take constant time, then Ө (n m!). If the dictionary is a binary tree or something like this where look-ups take Ө (log n) time, then Ө (n m! log n) Solution #2: (A) Tag each word in the dictionary with a vector containing the number of A’s, B’s, C’s, and so on, so that “cab” would be tagged with [1, 1, 1, 0, 0, … many 0’s … ], “babe” would be tagged with [1, 2, 0, 0, 1, 0, … many 0’s … ], and so forth. A word is then an anagram of another word if they both have the same tag. When tagging, create a pair of the word and its "tag" and store in a list.
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/21/2010 for the course CS 4102 taught by Professor Horton during the Spring '10 term at UVA.

Page1 / 4

hw1-s10-soln - CS 4102, Algorithms, HW1, Spring 2010...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online