Sie sind auf Seite 1von 2

Data Structure & Algorithms

CS210A,ESO207A,ESO211
Semester I, 2012-13, CSE, IIT Kanpur
Theoretical Assignment II
Deadline : 1st November
Note: Your solution for each exercise must be formal and complete. The design of each algorithm or
data structure must be provided in full details. You must provide analysis of time and space complexity
of each algorithm and data structure. You should give suitable and precise arguments to justify your
approach and/or prove the correctness of the algorithm (Do not write stories).
1 Splitting a red-black tree in O(log n) time (marks=30)
In the class we discussed an algorithm for Special merge(T
1
, T
2
) on a red-black tree. Design an algorithm
for Split(T, x) which splits T in to two red black trees T
1
and T
2
such that T
1
< x < T
2
. Your algorithm
must be based on Special merge(T
1
, T
2
) such that it invokes Special merge as a black box during its
execution. Your algorithm must run in O(log n) time only where n is the number of nodes in T. (You
will lose at most 5 marks if your algorithm takes O(log
2
n) time.)
2 Low Point in DFS traversal (marks=35)
Part 1 (the solution of this part is not to be submitted)
We discussed the problem of nding articulation points in a graph. For this we introduced a terminol-
ogy of High pt as follows. For a vertex v V , High pt(v) is the smallest DFN number of any ancestor of v
to which there is a back edge from subtree(v). We initialized High pt[v] of any vertex as . However, we
also realized that we could initialize High pt[v] to be DFN[v]. With this initialization, convince yourself
that the following becomes an alternative description of the denition of High pt of each vertex.
High pt[u]=
min{DFN[v]| a path from u to v consisting of zero or more tree edges followed by at most one back edge}.
Note that in this alternative description of High pt, we are considering paths in the following directed
graph obtained through DFS: Each tree edge directed away from the root (start vertex), and each non-
tree edge directed from descendant to ancestor.
Part 2
Let G = (V, E) be an undirected connected graph on n vertices and m edges given in the adjacency
lists representation. A DFS traversal has been performed on the graph. Observe that there will be n
distinct DFS calls during this traversal. Furthermore, there will be distinct times at which each of these
DFS calls start and nish for any vertex. So each vertex v V can be assigned two unique numbers
s(v) and f(v) from the range [0, 2n 1]. The number s(v) is the time at which DFS call for v was
invoked and the number f(v) is the time at which DFS call for v nishes. You are given two arrays
S and F of size n storing s(v) and f(v) for each vertex v. For example, if r is the vertex from where
we start the DFS traversal, then S[r] = 0 and F[r] = 2n 1. Given the graph G, and arrays S and
F, design an O(m+n) time algorithm that computes a function Low pt for every vertex dened as follows.
1
Low pt[u]=
max {DFN[v]| a path from u to v consisting of one or more tree edges and at most one back edge}.
Note that in the denition of Low pt(u) given above, the back edge need not be the last edge on the
path from u to v. To get a better understanding of the denition of Low pt, see Figure 1 where the
number on each vertex represents its DFN. You can observe that
Low pt(a)=10,Low pt(b)=10,Low pt(c)=10.
Low pt(d)=10,Low pt(e)=9,Low pt(g)=10.
Low pt(k)=10,Low pt(h)=7,Low pt(i)=10.
Low pt(j)=7.
a
b
c
d
g
h
i
j
1
3
2
6
7
9
4
5
e
k
8
10
Figure 1: A DFS tree along with the DFN numbering; the back edges are shown dotted.
3 A Gem from the world of Data structure (marks = 35)
Solve Exactly one of the following problems. You should choose that problem which you can solve fully
on your own.
1. You are given a sequence a
0
, . . . , a
n1
of n numbers. Design a suitable data structure which can
perform each of the following operations in O(log n) time for any 0 i j < n.
Report min(i, j): Report the smallest element from a
i
to a
j
.
Increment(i, j, x): Add x to each element from a
i
to a
j
.
2. You are given a sequence b
0
, . . . , b
n1
of n bits. Design a suitable data structure which can
perform each of the following operations in O(log n) time for any 0 i j < n.
Report bit(i): Report the value of bit b
i
.
Flip bits(i, j): Flip all bits from b
i
to b
j
. Here ipping a bit means changing it from 0 to 1 or
vice versa.
2

Das könnte Ihnen auch gefallen