Professional Documents
Culture Documents
Question 1 Solution
a)
b)
I. 111
II. 1000
III. 1001
IV. 1011
Question 2 Solution
1) Algo B is asymptotically more efficient. At n=451 value of 100nlogn is 405900 whereas value of 2n2
= 406802.
2) Algo A is asymptotically more efficient. At n=23 value of n5 is 6436343 whereas value of 2n is 8388608
3) Algo B is asymptotically more efficient. At n=1001 value of 5n is 5005 whereas value of 500 logn is
5000.
Question 3 Solution
Question 4 Solution
a) To see how the algorithm is not polynomial time in input size we have to see how the input is
encoded. In binary form the input n is a k-bit binary number. The loop runs 2k times and hence its
exponential in the size (k bits) of input.
b) A non-deterministic Turing machine(NTM) that can accept composite numbers binary uses
following steps
Every composite will be accepted by some branch of computation of NTM. The length of any
branch of computation is polynomial in number of bits so this is a non-deterministic polynomial
time algorithm that accepts composite numbers.
Even though we can solve this composite number problem on NTM in polynomial time, NTM is just
a conceptual mathematical model and no real world computer corresponding to NTM can be
created so we cannot use NTM polynomial time algorithm on real computers.