Beruflich Dokumente
Kultur Dokumente
OF
ADVANCED DATA
STRUCTUTRE
SUBMITTED TO:
SUBMITTED BY:
MR.MANISH SIR.
Sonika Dogra
RG 1005 A 19
Part A
Question 1 . Model a divide and conquer algorithm to
multiply two large integers using only additions and shift
operations.
ANSWER:
Procedure: multiply (A,B)
// assume A, B each have n bits
// the lower order bit of A will be written A[0],
// the highest will be A[n], same for B
let result = 0
let temp = 0
for j = 1 to n do
for i = 1 to n do
temp[i] = B[i] * A[j]
end for
shift temp by (j - 1) bits to the left
set result to result plus temp
set temp = 0
end for
return result
do
{
c = fgets(line, 80, fp); /* get a line of text */
if (c != NULL)
{
mix_up_the_chars(line);
}
} while (c != NULL);
fclose(fp);
return 0;
}
/* This function turns all upper case characters into lower case, */
/* and all lower case to upper case. It ignores all other */
/* characters. */
void mix_up_the_chars(char line[])
{
int index;
/* Result of execution
T(
5)
T3(3 T1(
) 2)
T2(
2) S(1) A(1)
K(1)
O(1) N(1)
4. Specify a brief account of at least two NP-hard or NP-
Complete practical problems and corresponding heuristics
being employed to solve them.
ANSWER:
The Travelling Salesman Problem (TSP) is an NP-hard
problem in combinatorial optimization studied in operations
research and theoretical computer science. Given a list of cities
and their pair wise distances, the task is to find a shortest
possible tour that visits each city exactly once.
The TSP has several applications even in its purest formulation,
such as planning, logistics, and the manufacture of microchips.
Slightly modified, it appears as a sub-problem in many areas,
such as DNA sequencing. In these applications, the concept city
represents, for example, customers, soldering points, or DNA
fragments, and the concept distance represents travelling times
or cost, or a similarity measure between DNA fragments. In many
applications, additional constraints such as limited resources or
time windows make the problem considerably harder.
Hamiltonian path problem: In the mathematical field of graph
theory the Hamiltonian path problem and the Hamiltonian cycle
problem are problems of determining whether a Hamiltonian path
or a Hamiltonian cycle exists in a given graph (whether directed
or undirected). Both problems are NP-complete. The problem of
finding a Hamiltonian cycle or path is in FNP. There is a simple
relation between the two problems. The Hamiltonian path
problem for graph G is equivalent to the Hamiltonian cycle
problem in a graph H obtained from G by adding a new vertex
and connecting it to all vertices of G. The Hamiltonian cycle
problem is a special case of the traveling salesman problem,
obtained by setting the distance between two cities to a finite
constant if they are adjacent and infinity otherwise.
This figure shows that a tree can have different spanning trees.
Generally, this approach is quite good for just about any value of
M. However, in certain situations some extra care is needed in the
selection of a suitable value for M. For example, it is often
convenient to make M an even number. But this means that h(x)
is even if x is even; and h(x) is odd if x is odd. If all possible keys
are equiprobable, then this is not a problem. However if, say,
even keys are more likely than odd keys, the function will not
spread the hashed values of those keys evenly.