This preview shows pages 1–2. Sign up to view the full content.
CS 573
Midterm 1 Questions
Fall 2010
This exam lasts 90 minutes.
Write your answers in the separate answer booklet.
Please return this question sheet with your answers.
1.
(a) Suppose
A
[
1..
n
]
is an array of
n
distinct integers, sorted so that
A
[
1
]
<
A
[
2
]
<
···
<
A
[
n
]
.
Each integer
A
[
i
]
could be positive, negative, or zero. Describe and analyze an efﬁcient
algorithm that either computes an index
i
such that
A
[
i
] =
i
or correctly reports that no such
index exists.
(b) Now suppose
A
[
1..
n
]
is a sorted array of
n
distinct
positive
integers. Describe and analyze
an even faster algorithm that either computes an index
i
such that
A
[
i
] =
i
or correctly
reports that no such index exists.
2. A
doubleHamiltonian circuit
a closed walk in a graph that visits every vertex exactly
twice
.
Prove
that it is NPhard to determine whether a given graph contains a doubleHamiltonian circuit.
b
d
c
f
g
a
e
This graph contains the doubleHamiltonian circuit
a
±
b
±
d
±
g
±
e
±
b
±
d
±
c
±
f
±
a
±
c
±
f
±
g
±
e
±
a
.
3. A palindrome is any string that is exactly the same as its reversal, like
I
, or
DEED
, or
HANNAH
, or
AMANAPLANACATACANALPANAMA
. Describe and analyze an algorithm to ﬁnd the length of the longest
subsequence of a given string that is also a palindrome.
For example, the longest palindrome subsequence of
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
This is the end of the preview. Sign up
to
access the rest of the document.
 Fall '08
 Chekuri,C
 Sort

Click to edit the document details