Cs 702 Final Term Solved
Cs 702 Final Term Solved
Q.#. 4. Write the pseudo code of Optimal Binary Search Tree (10)
Q.#. 6. Prove that for all integers n, if n2is divisible by 7 then n is divisible by
Ans. Prove that for all integers n, if n2 is divisible by 7 then n is divisible by 7.
Proof :
Q.#. 9. Prove that for all integers n, if n2 is even then n is also even.
Ans.
Q.#. 15. Prove that every connected graph has a spanning tree (5)
Ans.
If the graph has no cycles but is connected, it is a tree; and thus is its own
spanning tree. This makes a good base step for a proof by induction on the
number of cycles of the graph that every connected graph has a spanning tree.
Suppose inductively that when c>0 and a connected graph has fewer than c
cycles, then the graph have a spanning tree.
Suppose that G is a graph with c cycles. Choose a cycle of G and choose and edge
of that cycle. Deleting that edge (but not its endpoint) reduces the number of
cycles by at least one, and so our inductive hypothesis implies that the resulting
graph has a spanning tree. But then that spanning tree is also a spanning tree of G.
Q.#. 18. Write the pseudo code of Fast Fourier Transform (FFT) recursive algorithm.
Ans.
Q.#. 26. With the help of Chinese remainder theorm solve following (10 marks)
Q.#. 29. Write the pseudo code of Naïve String Matching Algorithm. (5)
Ans.
Q.#. 31. A binary tree is not fully corresponding with optimal prefix prove it? ( 5 markx)
Ans.
Let T be a binary tree corresponds to prefix code such that T is not full. Then there must exist an
internal node, say x, such that x has only one child, y. Construct another binary tree, T`, which has
save leaves as T and have same depth as T except for the leaves which are in the sub tree rooted at
y in T. These leaves will have depth in T`, which implies T cannot correspond to an optimal prefix
code.
To obtain T`, simply merge x and y into a single node, z is a child of parent of x (if a parent exists)
and z is a parent to any children of y. Then T` have the desired properties: it corresponds to a code
on the same alphabet as the code which are obtained, in the sub tree rooted at y in T have depth in
T` strictly less (by one) than their depth in T.
T
h a b c d e F
iFrequency 45,000 13,000 12,000 16,000 9,000 5,000
s
Fixed Length code 000 001 010 011 100 101
cVariable-length Code 0 101 100 111 1101 1100
Note:
Q.#. 40. Explain the sitiation in which greedy algorithm does not work?