ASSIGNMENT OF MCS-031(ADA) Question 1: (a) Show, through appropriate examples or otherwise, that the following three characteristics of an algorithm are independent (i) finiteness An algorithm must terminate after a finite number of steps and further each step must be executable in finite amount of time. In order to establish a sequence of steps as an algorithm, it should be established that it terminates (in finite number of steps) on all allowed inputs. (ii) definiteness Each steps of an algorithm must be precisely defined; the action to be carried out must be rigorously and unambiguously specified for each case. (iii) effectiveness it consists of basic instructions that are realizable. This means that the instructions can be performed by using the given inputs in a finite amount of time. (c) Arrange the following growth rates in increasing order: O ( (24)n ), O (n2), O (1), O (n log n) ANS- Order Of Notaion In Increasing Order:- 0(1) O(n) 1/2 o(n) o(nlogn) o(n 2 ) o(n 3 ) o(2 n ) order is o(1) < o(n logn) < o(n 2 ) < o(24 n )
(b) Let f (n) denote the nth term of a sequence of integers given (5 marks) by the equation f(n) = f(n-1) +f(n-2) for n > 2 and f(1) = 1 and f(2) = 1, then using principle of mathematical induction, show that 5 f( n ) = {(1+ 5) / 2} n -- {(1 -- 5) / 2}n for all n > = 1
ANS- For 100% Result Oriented IGNOU Coaching and Project
Question 2: Suppose that instead of binary or decimal representation ofintegers, we have ternary, along with 3 s complement,representation of integers, i.e., integers are represented using threedigits, viz., 0, 1,2. For example, the integer 47 is represented as01202 = (in decimal) 1. 33 + 2. 32 + 0. 31 + 2. 30, where, the leading zero indicates positive sign. And the integer ( 47 ) in 3 scomplement is represented by 11021, the leading 1 indicatesnegative sign. The other digits, except the right-most, in therepresentation of ( 47) are obtained by subtracting from 2 thecorresponding digit in 47 s representation, and then adding 1 (therepresentation of 47 is obtained as 11020 + 00001).Write a program for the arithmetic (negation of an integer,addition, subtraction and multiplication of two integers) of 4integers using 3 s complement representation. The program should include a procedure for calculating each of negation of an integer, addition, subtraction and multiplication of two integers. The integers will use 8-ternary digit positions, in which the left-most position will be used for sign. Using your program find the ternary representation of each of thedecimal numbers 345, -- 297, 18 and ( (345 -- 297) * 18) ans- Question 3: (a) Write a short note on each of the following: (i) Best case analysis In the best case analysis, we calculate lower bound on running time of an algorithm. We must know the case that causes minimum number of operations to be executed. In the linear search problem, the best case occurs when x is present at the first location. The number of operations in worst case is constant (not dependent on n). So time complexity in the best case would be o(1). (ii) amortized analysis This term refers to the analysis of algorithm performance based on a specific sequence of operations that targets the worst case scenario -- that is, amortized analysis does imply that the metric is worst case performance (although it still does not say which quantity is being measured). To perform this analysis, we need to specify the size of the input, but we do not need to make any assumptions about its form. In layman's terms, amortized analysis is picking an arbitrary size for the input and then "playing through" the algorithm. Whenever a decision that depends on the input must be
made, the worst path is taken¹. After the algorithm has run to completion we divide the calculated complexity by the size of the input to produce the final result. (b) Using one-by-one (i) bubble sort (ii) heap sort and (iii) quick sort, sort the following sequence in increasing order and analyze (i.e., find number of comparisons and assignments in each of ) the algorithm: 43, 28, 37, 18, 15, 40, 12 ans-
Question 4:
(a) The following pseudo-code is given to compute ( a b )mod n, where a, b and n are positive integers. Trace the algorithm to compute 7 560 mod 561 MODULAR-EXPONENTION (a, b, n) 1. c 0 { variable c is assigned 0} 2. d 1 3. let (bk, bk -- 1,, B0) be binary representation of b 4. for i k downto 0 5. do c 2c 6. d (d. d) mod n 7. if bi = 1 8. then c c+1 9. d (d. a) mod n 10. end-do 11. return d. (b) Explain the essential idea of Dynamic Programming. How does Dynamic Programming differ from Divide and conquer approach for solving problems? Ans Dynamic Programming is a technique for solving problems with overlapping subproblems. Each sub-problem is solved only once and the result of each sub-problem is stored in a table ( generally implemented as an array or a hash table) for future references. These sub-solutions may be used to obtain the original solution and the technique of storing the sub-problem solutions is known as memoization. Dynamic Programming Breaks the problem down into discrete subproblems. The recursive algorithm for the Fibonacci sequence is an example of Dynamic Programming, because it solves for fib(n) by first solving for fib(n-1). In order to solve the original problem, it solves a different problem. Divide and Conquer These algorithms typically solve similar pieces of the problem, and then put them together at the end. Mergesort is a classic example of divide and conquer. The main difference between this example and the Fibonacci example is that in a mergesort, the division can (theoretically) be arbitrary, and no matter how you slice it up, you are still merging and sorting. The same amount of work has to be done to mergesort the array, no matter how you divide it up. Solving for fib(52) requires more steps than solving for fib(2).
Question 5: (a) For the graph given in Figure below, use DFS to visit various vertices. The vertex B is taken as the starting vertexand, if there are more than one vertices adjacent to a vertex,then the adjacent vertices are visited in lexicographic order. (b) In context of graph search, explain the minimax principle. Ans- Minimizing the maximum losses that could occur in an event or situation is this specific type of decision-making principle. Should a strategy fail, this financial and business strategy measures potential results leading to the least amount of regret. By the use of logic, determine and use this strategy. Aids deciding when presented with two various and conflicting strategies. A principle for decision-making by which, when presented with two various and conflicting strategies, one should, by the use of logic, determine and use the strategy that will minimize the maximum losses that could occur. This financial and business strategy strives to attain results that will cause the least amount of regret, should the strategy fail.
Question 6: (a) Is there a greedy algorithm for every interesting optimization problems? Justify your Claim. Ans- A greedy algorithm is an algorithm that follows the problem solving heuristic of making the locally optimal choice at each stage with the hope of finding a global optimum. In many problems, a greedy strategy does not in general produce an optimal solution, but nonetheless a greedy heuristic may yield locally optimal solutions that approximate a global optimal solution in a reasonable time. For example, a greedy strategy for the traveling salesman problem (which is of a high computational complexity) is the following heuristic: "At each stage visit an unvisited city nearest to the current city". This heuristic need not find a best solution but terminates in a reasonable number of steps; finding an optimal solution typically requires unreasonably many steps. (b) Apply each of (i) Prim s and (ii)kruskal s algorithms one at a time to find minimal spanning tree for the following graph.
Question 7: Write note on each of the following: (20 marks) (i) Unsolvability/ undecidability of a problem (ii) Halting problem (iii) Reduction of a problem for determining decidability (iv) Rice theorem ans- In computability theory, Rice's theorem states that, for any non-trivial property of partial functions, there is no general and effective method to decide whether an algorithm computes a partial function with that property. Here, a property of partial functions is called trivial if it holds for all partial computable functions or for none, and an effective decision method is called general if it decides correctly for every algorithm. (v) Post correspondence problem (vi) NP-complete problem (vii) K-colourability problem (viii) Independent set problem