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
!).
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
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!) lookups in the dictionary.
If the dictionary uses a hashtable or some kind of index where lookups take constant time, then
Ө
(n m!).
If the dictionary is a binary tree or something like this where lookups 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.
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '10
 HORTON
 Algorithms, Mathematical Induction, Inductive Reasoning, US standard clothing size, fake coin, size Ⱥ02 Ⱥ05

Click to edit the document details