Vous êtes sur la page 1sur 34

MCS-031

Qst1. (a) Arrange the following growth rates in increasing order: O ((23)n ) , O (n4), O (1), O (n 3log n)

Qst1. (b) Show, through appropriate examples or otherwise, that the following three characteristics of
an algorithm are independent of each other. (i.e., a method may have one of these properties, without
having the other two): finiteness (ii) definiteness (iii) effectiveness.

Ans 1. Finiteness: An algorithm must terminate after a finite number of steps and Algorithmics 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.
2. Definiteness: (no ambiguity): Each step of an algorithm must be precisely defined; the action to be carried
out must be rigorously and unambiguously specified for each case. Through the next example, we show how an
instruction may not be definite. Method which is effective (to be explained later) but not definite.

For More Solutions Contact To Mr. Bilal Ali : Brain Caf Computer Classes, Near U.P.
Tech. Chowk Lucknow. Contact Number:+91 9984736691,+91 9450148850
E_Mail_ID- belaal.ali@gmail.com@gmail.com, FB Page- facebook.com/bilalali0786 1
MCS-031

The following is a program fragment for the example method:


x1
Toss a coin,
If the result is Head then x 3 else x 4
{in the above, the symbol denotes that the value on its R.H.S is assigned to the variable on its L.H.S.
Detailed discussion under. All the steps, like tossing the coin etc., can be (effectively) carried out. However, the
method is not definite, as two different executions may yield different outputs.
3.Effectiveness: An algorithm should be effective. This means that each of the operation to be performed in
an algorithm must be sufficiently basic that it can, in principle, be done exactly and in a finite length of time,
by a person using pencil and paper. It may be noted that the FINITENESS condition is a special case of
EFFECTIVENESS. If a sequence of steps is not finite, then it can not be effective also.
A method may be designed which is a definite sequence of actions but is not finite (and hence not effective)
Example 1: If the following instruction is a part of an algorithm:
Find exact value of e using the following formula
e = 1+ 1/(1!) + 1/(2!) + 1/(3!) +..
and add it to x.
Then, the algorithm is not effective, because as per instruction, computation of e requires computation of
infinitely many terms of the form 1/n! for n = 1, 2, 3, .., which is not possible/effective.
However, the instruction is definite as it is easily seen that computation of each of the term 1/n! is definite (at
least for a given machine).
Qst1. (c) Write a recursive procedure for the sum of first n natural numbers. Then explain how your
algorithm computes product of first 6 natural numbers.
Ans: A procedure, which can call itself, is said to be recursive Algorithmics procedure/algorithm. For
successful implementation of the concept of recursive procedure, the following conditions should be satisfied.
(i) There must be in-built mechanism in the computer system that supports the calling of a procedure by itself,
e.g, there may be in-built stack operations on a set of stack registers.
(ii) There must be conditions within the definition of a recursive procedure under which, after finite number of
calls, the procedure is terminated.
(iii) The arguments in successive calls should be simpler in the sense that each succeeding argument takes us
towards the conditions mentioned in (ii).
For More Solutions Contact To Mr. Bilal Ali : Brain Caf Computer Classes, Near U.P.
Tech. Chowk Lucknow. Contact Number:+91 9984736691,+91 9450148850
E_Mail_ID- belaal.ali@gmail.com@gmail.com, FB Page- facebook.com/bilalali0786 2
MCS-031

In view of the significance of the concept of procedure, and specially of the concept of recursive procedure, in
solving some complex problems, we discuss another recursive algorithm for the problem of finding the sum of
first n natural numbers, discussed earlier. For the discussion, we assume n is a non-negative integer
procedure SUM (n : integer) : integer
s : integer;
If n = 0 then return (0)
else
begin s n + SUM (n 1);
return (s)
end;
end;
algorithm For computes product of first 6 natural numbers
As n=6 0
therefore
S6 n*SUM (n-1) = 6*MULT(4)
{It may be noted that in different calls of the procedure SUM, the variable names occurring within the
procedure, denote different variables. This is why instead of S we use the names Si for i=6, 5,4,3,}
Therefore, in order to compute MULT(5), we need to compute MULT (4)
n=4 0, therefore
S4 4*MULT(3)
Continuing like this, we get
S3 3* MULT (2)
S2 2 * MULT (1)
S1 1 * MULT (0)
At this stage n=0, and accordingly, the algorithm returns value 0. Substituting the value o of MULT(0) we get
S1= 1*0=1 which is returned by MULT (1). Substituting this value we get S2=3. Continuing like this, we get
S6=720.

Qst1. (d) In respect of understanding a problem for solving it using a computer, explain understanding
the problem step.

For More Solutions Contact To Mr. Bilal Ali : Brain Caf Computer Classes, Near U.P.
Tech. Chowk Lucknow. Contact Number:+91 9984736691,+91 9450148850
E_Mail_ID- belaal.ali@gmail.com@gmail.com, FB Page- facebook.com/bilalali0786 3
MCS-031

Ans: Understanding allows appropriate action. This step forms the basis of the other steps to the discussed. For
understanding the problem, we should read the statement of the problem, if required, a number of times. We
should try to find out.
(i) the type of problem, so that if a method of solving problems of the type, is already known, then the known
method may be applied to solve the problem under consideration.
(ii) the type of inputs and the type of expected/desired outputs, specially, the illegal inputs, i.e., inputs which
are not acceptable, are characterized at this stage. For example, in a problem of calculating income-tax, the
income can not be non-numeric character strings.
(iii) the range of inputs, for those inputs which are from ordered sets. For example, in the problem of finding
whether a large number is prime or not, we can not give as input a number greater than the Maximum number
(Max, mentioned above) that the computer system used for the purpose, can store and arithmetically operate
upon. For still larger numbers, some other representation mechanism has to be adopted.
(iv) special cases of the problem, which may need different treatment for solving the problem. For example, if
for an expected quadratic equation ax2+bx+c=0, a, the coefficient of x2, happens to be zero then usual method
of solving quadratic equations, discussed earlier in this unit, can not be used for the purpose.

Qst 2. Suppose that instead of binary or decimal representation of integers, we have ternary, along with
3s complement, representation of integers, i.e., integers are represented using three digits, viz., 0, 1,2.
For example, the integer 47 is represented as 01202 = (in decimal) 1. 33 + 2. 32 + 0. 31 + 2. 30, where, the
leading zero indicates positive sign. And the integer (- 47 ) in 3s complement is represented by 11021, the
leading 1 indicates negative sign. The other digits, except the right-most, in the representation of ( 47)
are obtained by subtracting from 2 the corresponding digit in 47s representation, and then adding 1 (the
representation 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 integers using 3s 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 the decimal numbers 267 and 503.
Ans: Coming Soon .. Contact for Solution Lucknow Computer Clasess

For More Solutions Contact To Mr. Bilal Ali : Brain Caf Computer Classes, Near U.P.
Tech. Chowk Lucknow. Contact Number:+91 9984736691,+91 9450148850
E_Mail_ID- belaal.ali@gmail.com@gmail.com, FB Page- facebook.com/bilalali0786 4
MCS-031

Qst3. (a) Write a short note on each of the following:


Ans- (i) Average case analysis: In this respect, average-case analysis is more informative than its two just-
mentioned counter-parts, particularly, when the algorithm is to be used frequently and on varied types of inputs.
In order to get really useful information from the average-case analysis of an algorithm, we must explicitly
mention the properties of the set of inputs, obtained either through empirical evidence or on the basis of
theoretical analysis. We explain the ideas through the analysis of the following algorithm, that, for given an
element K and an array A[1..n], returns the index i in the array A[1..n], if A[ i ] = K otherwise returns 0.

Through the above example we have obtained an idea of how we may proceed to find average-case complexity
of an algorithm. Next we outline the process of findingaverage-case complexity of any algorithm, as follows:
(i) First categories all possible input instances into classes in such a way that inputs in the same class require or
are expected to require the execution of the same number of the basic operation(s) of the algorithm.
(ii) Next, the probability distribution of the inputs for different class as, is obtained empirically or assumed on
some theoretical grounds.
(iii) Using the process as discussed in the case of Sequential-Search above, we compute the average-case
complexity of the algorithm.
It is worth mentioning explicitly that average-case complexity need not be the average of the worst-case
complexity and best-case complexity of an algorithm, though in some cases, the two may coincide.Further, the
effort required for computing the average-case, is worth in view of its contribution in the sense, that in some
cases, the average-case complexity is much better than the Worst-Case Complexity. For example, in the case of
Quicksort algorithm, which we study later, for sorting an array of elements, the Worst-Case complexity is a

For More Solutions Contact To Mr. Bilal Ali : Brain Caf Computer Classes, Near U.P.
Tech. Chowk Lucknow. Contact Number:+91 9984736691,+91 9450148850
E_Mail_ID- belaal.ali@gmail.com@gmail.com, FB Page- facebook.com/bilalali0786 5
MCS-031

quadratic function whereas the average-case complexity is bounded by some constant multiple of n log n. For
large values of n, a constant multiple of
(n log n) is much smaller than a quadratic function of n. Thus, without average-case
analysis, we may miss many on-the-average good algorithms.
amortized analysis : (i) worst-case and best-case analyses of an algorithm may not give a good idea
about the behaviour of the algorithm on a typical or random input.
(ii) validity of the conclusions derived from average-case analysis depends on the
quality of the assumptions about probability distribution of the inputs of a given
size.

Another important fact that needs our attention is the fact that most of the operations, including the most time-
consuming operations, on a data structure (used for solving a problem) do not occur in isolation, but different
operations, with different time complexities, occur as a part of a sequence of operations. Occurrences of a
particular operation in a sequence of operations are dependent on the occurrences of other operations in the
sequence. As a consequence, it may happen that the most time consuming operation can occur but only rarely
or the operation only rarely consumes its theoretically determined maximum time. We will support our claim
later through an example. But, we continue with our argument in support of the need for another type of
analysis, viz.,
(ii)Amortized analysis: for better evaluation of the behaviour of an algorithm. However, this fact of
dependence of both the occurrences and complexity of an operation on the occurrences of other operations, is
not taken into consideration in the earlier mentioned analyses. As a consequence, the complexity of an
algorithm is generally over-evaluated. Introduction to Algorithmics
Next, we give an example in support of our claim that the frequencies of occurrences of operations and
their complexities, are generally interdependent and hence the impact of the most time-consuming operation
may not be as bad as it is assumed or appears to be.
Example, We define a new data structure say MSTACK, which like the data structure STACK has the usual
operations of PUSH and POP. In addition there is an operation MPOP(S, k), where S is a given stack and k is a
non-negative integer. Then MPOP(S, k) removes top k elements of the stack S, if S has at least k elements in
the stack. Otherwise it removes all the elements of S. MPOP (S, k) may be formallydefined as

For More Solutions Contact To Mr. Bilal Ali : Brain Caf Computer Classes, Near U.P.
Tech. Chowk Lucknow. Contact Number:+91 9984736691,+91 9450148850
E_Mail_ID- belaal.ali@gmail.com@gmail.com, FB Page- facebook.com/bilalali0786 6
MCS-031

Qst3. (b) Using one-by-one (i) insertion sort (ii)heap sort and (iii) merge sort, sort the following sequence
in increasing order and analyze (i.e., find number of comparisons and assignments in each of ) the
algorithm: 94, 45, 57, 18, 82, 17, 56, 40, 12 ,107
Ans: (i) insertion sort :
Algorithm: The Insertion Sort

For More Solutions Contact To Mr. Bilal Ali : Brain Caf Computer Classes, Near U.P.
Tech. Chowk Lucknow. Contact Number:+91 9984736691,+91 9450148850
E_Mail_ID- belaal.ali@gmail.com@gmail.com, FB Page- facebook.com/bilalali0786 7
MCS-031

For More Solutions Contact To Mr. Bilal Ali : Brain Caf Computer Classes, Near U.P.
Tech. Chowk Lucknow. Contact Number:+91 9984736691,+91 9450148850
E_Mail_ID- belaal.ali@gmail.com@gmail.com, FB Page- facebook.com/bilalali0786 8
MCS-031

For More Solutions Contact To Mr. Bilal Ali : Brain Caf Computer Classes, Near U.P.
Tech. Chowk Lucknow. Contact Number:+91 9984736691,+91 9450148850
E_Mail_ID- belaal.ali@gmail.com@gmail.com, FB Page- facebook.com/bilalali0786 9
MCS-031

The insertion sort, algorithm for sorting a list L of n numbers represented by an array A[1..n] proceeds by
picking up the numbers in the array from left one by one and each newly picked up number is placed at its
relative position, w.r.t the sorting order, among the earlier ordered ones. The process is repeated till the each
element of the list is placed at its correct relative position, i.e., when the list is sorted.

For More Solutions Contact To Mr. Bilal Ali : Brain Caf Computer Classes, Near U.P.
Tech. Chowk Lucknow. Contact Number:+91 9984736691,+91 9450148850
E_Mail_ID- belaal.ali@gmail.com@gmail.com, FB Page- facebook.com/bilalali0786 10
MCS-031

For More Solutions Contact To Mr. Bilal Ali : Brain Caf Computer Classes, Near U.P.
Tech. Chowk Lucknow. Contact Number:+91 9984736691,+91 9450148850
E_Mail_ID- belaal.ali@gmail.com@gmail.com, FB Page- facebook.com/bilalali0786 11
MCS-031

(ii)heap sort : Heap is an array H[1..n] in which every element in position i (the parent) in the first half of the
array is greater than or equal to elements in positions 2i and and 2i+1 (the children):
HEAP SORT is a three-step algorithm as discussed below:
(i) Heap Construction for the a given array
(ii) (Maximum deletion) Copy the root value (which is maximum of all values in the Heap) to right-most yet-
to-be occupied location of the array used to store the sorted values and copy the value in the last node of the tree
(or of the corresponding array) to the root.
(iii) Consider the binary tree (which is not necessarily a Heap now) obtained from the Heap through the
modifications through Step (ii) above and by removing currently the last node from further consideration.
Convert the binary tree into a Heap by suitable modifications.
This value is copied in B[1] and the Heap Sort algorithm terminates.
Next, we consider the two procedure
1. Build-Heap

For More Solutions Contact To Mr. Bilal Ali : Brain Caf Computer Classes, Near U.P.
Tech. Chowk Lucknow. Contact Number:+91 9984736691,+91 9450148850
E_Mail_ID- belaal.ali@gmail.com@gmail.com, FB Page- facebook.com/bilalali0786 12
MCS-031

For More Solutions Contact To Mr. Bilal Ali : Brain Caf Computer Classes, Near U.P.
Tech. Chowk Lucknow. Contact Number:+91 9984736691,+91 9450148850
E_Mail_ID- belaal.ali@gmail.com@gmail.com, FB Page- facebook.com/bilalali0786 13
MCS-031

For More Solutions Contact To Mr. Bilal Ali : Brain Caf Computer Classes, Near U.P.
Tech. Chowk Lucknow. Contact Number:+91 9984736691,+91 9450148850
E_Mail_ID- belaal.ali@gmail.com@gmail.com, FB Page- facebook.com/bilalali0786 14
MCS-031

Delete-Root-n-Rebuild.

For More Solutions Contact To Mr. Bilal Ali : Brain Caf Computer Classes, Near U.P.
Tech. Chowk Lucknow. Contact Number:+91 9984736691,+91 9450148850
E_Mail_ID- belaal.ali@gmail.com@gmail.com, FB Page- facebook.com/bilalali0786 15
MCS-031

For More Solutions Contact To Mr. Bilal Ali : Brain Caf Computer Classes, Near U.P.
Tech. Chowk Lucknow. Contact Number:+91 9984736691,+91 9450148850
E_Mail_ID- belaal.ali@gmail.com@gmail.com, FB Page- facebook.com/bilalali0786 16
MCS-031

(iii) merge sort : In this method, we recursively chop the list into two sublists of almost equal sizes and when
we get lists of sizes one, then start sorted merging of lists in the reverse order in which these lists were obtained
through chopping. The following example clarifies the method.

For More Solutions Contact To Mr. Bilal Ali : Brain Caf Computer Classes, Near U.P.
Tech. Chowk Lucknow. Contact Number:+91 9984736691,+91 9450148850
E_Mail_ID- belaal.ali@gmail.com@gmail.com, FB Page- facebook.com/bilalali0786 17
MCS-031

Procedure mergesort (A [1..n])


if n > 1 then
m [n/2]
L1 A[1..m]
L2 A[m+1..n]
L merge (mergesort (L1), mergesort (L2))
end
begin {of the procedure}
{L is now sorted with elements in nondecreasing order}
Next, we discuss merging of already sorted sublists
Procedure merge (L1, L2: lists)
L empty list
While L1 and L2 are both nonempty do
begin
Remove smaller of the first elements of L1 and L2 from the list it is in and place it in L, immediately next
to the right of the earlier elements in L. If removal of this element makes one list empty then remove all
elements from the other list and append them to L keeping the relative order of the elements intact.
else repeat the process with the new lists L1 and L2
end

Qst.4 Explain the essential idea of each of the following


i) Divide and conquer: The Divide and Conquer is a technique of solving problems from various domains
and will be discussed in details later on. Here, we briefly discuss how to use the technique in solving sorting
problems.
A sorting algorithm based on Divide and Conquer technique has the following
outline:
Procedure Sort (list)
If the list has length 1 then return the list
Else {i.e., when length of the list is greather than 1}

For More Solutions Contact To Mr. Bilal Ali : Brain Caf Computer Classes, Near U.P.
Tech. Chowk Lucknow. Contact Number:+91 9984736691,+91 9450148850
E_Mail_ID- belaal.ali@gmail.com@gmail.com, FB Page- facebook.com/bilalali0786 18
MCS-031

begin
Partition the list into two sublists say L and H,
Sort (L)
Sort (H)
Combine (Sort (L)), Sort (H))
{during the combine operation, the sublists are merged in sorted order}
end.
There are two well-known Divide and conquer methods for sorting viz:
(i) Merge Sort
(ii) Quick Sort

ii) Dynamic Programming : Dynamic Programming, may prove quite useful. This unit is devoted to
developing algorithms using Dynamic Programming technique. But before, we discuss the technique in more
details, let us briefly discuss underlying idea of the technique and the fundamental difference between Dynamic
Programming and Divide-and-Conquer technique.
Essential idea of Dynamic Programming, being quite simple, is that we should avoid calculating the same
quantity more than once, usually by keeping a table of known results for simpler instances. These results, in
stead of being calculated repeatedly, can be retrieved from the table, as and when required, after first
computation. Comparatively, Divide-and-Conquer is conceptually a top-down approach for solving problems
or developing algorithms, in which the problem is attempted initially with complete instance and gradually
replacing the more complex instances by simpler instances.
On the other hand, Dynamic Programming is a bottom-up approach for solving problems, in which we first
attempt the simplest subinstances of the problem under consideration and then gradually handle more and more
complex instances, using the results of earlier computed (sub) instances.

iii) The Greedy Approach: A greedy algorithm is a mathematical process that looks for simple, easy-to-
implement solutions to complex, multi-step problems by deciding which next step will provide the most
obvious benefit. Such algorithms are called greedy because while the optimal solution to each smaller instance
will provide an immediate output, the algorithm doesnt consider the larger problem as a whole. Once a
decision has been made, it is never reconsidered. Greedy algorithms work by recursively constructing a set of

For More Solutions Contact To Mr. Bilal Ali : Brain Caf Computer Classes, Near U.P.
Tech. Chowk Lucknow. Contact Number:+91 9984736691,+91 9450148850
E_Mail_ID- belaal.ali@gmail.com@gmail.com, FB Page- facebook.com/bilalali0786 19
MCS-031

objects from the smallest possible constituent parts. Recursion is an approach to problem solving in which the
solution to a particular problem depends on solutions to smaller instances of the same problem. The advantage
to using a greedy algorithm is that solutions to smaller instances of the problem can be straightforward and easy
to understand. The disadvantage is that it is entirely possible that the most optimal short-term solutions may
lead to the worst possible long-term outcome.
Greedy algorithms are often used in ad hoc mobile networking to efficiently route packets with the fewest
number of hops and the shortest delay possible. They are also used in machine learning, business intelligence
(BI), artificial intelligence (AI) and programming.

Example :
Greedy algorithms determine minimum number of coins to give while making change. These are the steps a
human would take to emulate a greedy algorithm to represent 36 cents using only coins with values {1, 5, 10,
20}. The coin of the highest value, less than the remaining change owed, is the local optimum. (Note that in
general the change-making problem requires dynamic programming or integer programming to find an optimal
solution; however, most currency systems, including the Euro and US Dollar, are special cases where the
greedy strategy does find an optimal solution.)

For More Solutions Contact To Mr. Bilal Ali : Brain Caf Computer Classes, Near U.P.
Tech. Chowk Lucknow. Contact Number:+91 9984736691,+91 9450148850
E_Mail_ID- belaal.ali@gmail.com@gmail.com, FB Page- facebook.com/bilalali0786 20
MCS-031

Qst 5. (a) For the graph given in Figure below, use DFS to visit various vertices. The vertex C is taken as
the starting vertex and, if there are more than one vertices adjacent to a vertex, then the adjacent vertices
are visited in lexicographic order.
Ans:

For More Solutions Contact To Mr. Bilal Ali : Brain Caf Computer Classes, Near U.P.
Tech. Chowk Lucknow. Contact Number:+91 9984736691,+91 9450148850
E_Mail_ID- belaal.ali@gmail.com@gmail.com, FB Page- facebook.com/bilalali0786 21
MCS-031

Qst.5 (b) In context of graph search, explain the minimax principle.


Ans: The Minimax Principle Whichever search technique we may use, it can be seen that many graph
problems including game problems, complete searching of the associated graph is not possible. The alternative
is to perform a partial search or what we call a limited horizon search from the current position. This is the
principle behind the minimax procedure.
Minimax is a method in decision theory for minimizing the expected maximum loss. It is applied in two
players games such as tic-tac-toe, or chess where the two players take alternate moves. It has also been extended
to more complex games which require general decision making in the presence of increased uncertainty. All

For More Solutions Contact To Mr. Bilal Ali : Brain Caf Computer Classes, Near U.P.
Tech. Chowk Lucknow. Contact Number:+91 9984736691,+91 9450148850
E_Mail_ID- belaal.ali@gmail.com@gmail.com, FB Page- facebook.com/bilalali0786 22
MCS-031

these games have a common property that they are logic games. This means that these games canbe described
by a set of rules and premises. So it is possible to know at a given point of time, what are the next available
moves. We can also call them full information games as each player has complete knowledge about possible
moves of the adversary.
In the subsequent discussion of games, the two players are named as MAX and MIN. We are using an
assumption that MAX moves first and after that the two players will move alternatively. The extent of search
before each move will depend o the play depth the amount of lookahead measured in terms of pairs of
alternating moves for MAX and MIN.
In the algorithm, lookahead limit represents the lookahead factor in terms of number of steps, u and v
represent game states or nodes, maxmove() and minmove() are functions to describe the steps taken by player
MAX or player MIN to choose a move, efun() is the static evaluation function which attaches a positive or
negative integer value to a node ( i.e., a game state), value is a simple variable.
Now to move number of steps equal to the lookahead limit from a given game state u, MAX should move to
the game state v given by the following code :

For More Solutions Contact To Mr. Bilal Ali : Brain Caf Computer Classes, Near U.P.
Tech. Chowk Lucknow. Contact Number:+91 9984736691,+91 9450148850
E_Mail_ID- belaal.ali@gmail.com@gmail.com, FB Page- facebook.com/bilalali0786 23
MCS-031

We can see that in the minimax technique, player MIN tries to minimize te advantage he allows to player MAX,
and on the other hand player MAX tries to maximize the advantage he obtains after each move.

Let us suppose the graph given below shows part of the game. The values of leaf nodes are given using
efun() procedure for a particular game then the value of nodes above can be calculated using minimax
principle.Suppose the lookahead limit is 4 and it is MAXs turn.

For More Solutions Contact To Mr. Bilal Ali : Brain Caf Computer Classes, Near U.P.
Tech. Chowk Lucknow. Contact Number:+91 9984736691,+91 9450148850
E_Mail_ID- belaal.ali@gmail.com@gmail.com, FB Page- facebook.com/bilalali0786 24
MCS-031

Qst.6 Apply each of (i) Prims and (ii)Kruskals algorithms one at a time to find minimal spanning tree
for the following graph
Ans: Given Graph is:

For More Solutions Contact To Mr. Bilal Ali : Brain Caf Computer Classes, Near U.P.
Tech. Chowk Lucknow. Contact Number:+91 9984736691,+91 9450148850
E_Mail_ID- belaal.ali@gmail.com@gmail.com, FB Page- facebook.com/bilalali0786 25
MCS-031

For More Solutions Contact To Mr. Bilal Ali : Brain Caf Computer Classes, Near U.P.
Tech. Chowk Lucknow. Contact Number:+91 9984736691,+91 9450148850
E_Mail_ID- belaal.ali@gmail.com@gmail.com, FB Page- facebook.com/bilalali0786 26
MCS-031

Qst.7 Write note on each of the following:


(i) Independent set problem : Independent set problem: Given a graph G = (V, E) and a positive integer k,
is there an independent set of vertices with at least k elements? Explanation: A subset V1 of the set of
vertices V of graph G is said to be independent, if no two distinct vertices in V1 are adjacent. For example, in
the above graph V1 = {1, 4} is an independent set.
(ii) K-colourability problem: Given a graph G and a positive integer k, is there a k-colouring of G?
Explanation: A k-colouring of G is an assignment to each vertex of one of the k colours so that no two adjacent
vertices have the same color. It may be recalled that two vertices in a graph are adjacent if there is an edge
between the two vertices.

As the vertices 1, 2, 3 are mutually adjacent therefore, we require at least three colours for k-colouring problem.

(iii) Unsolvability/ undecidability of a problem : In computability theory and computational complexity


theory, an undecidable problem is a decision problem for which it is known to be impossible to construct a
single algorithm that always leads to a correct yes-or-no answer. A decision problem is any arbitrary yes-or-no
question on an infinite set of inputs. Because of this, it is traditional to define the decision problem equivalently
as the set of inputs for which the problem returns yes. These inputs can be natural numbers, but also other
values of some other kind, such as strings of a formal language. Using some encoding, such as a Gdel

For More Solutions Contact To Mr. Bilal Ali : Brain Caf Computer Classes, Near U.P.
Tech. Chowk Lucknow. Contact Number:+91 9984736691,+91 9450148850
E_Mail_ID- belaal.ali@gmail.com@gmail.com, FB Page- facebook.com/bilalali0786 27
MCS-031

numbering, the strings can be encoded as natural numbers. Thus, a decision problem informally phrased in
terms of a formal language is also equivalent to a set of natural numbers. To keep the formal definition simple,
it is phrased in terms of subsets of the natural numbers.
Formally, a decision problem is a subset of the natural numbers. The corresponding informal problem is
that of deciding whether a given number is in the set. A decision problem A is called decidable or effectively
solvable if A is a recursive set. A problem is called partially decidable, semi-decidable, solvable, or provable if
A is a recursively enumerable set. This means that there exists an algorithm that halts eventually when the
answer is yes but may run for ever if the answer is no. Partially decidable problems and any other problems that
are not decidable are called undecidable

(iv) Halting problem : Informally, the Halting problem can be put as: Given a Turing machine M and an
input w to the machine M, determine if the machine M will eventually halt when it is given input w.
Trial solution: Just run the machine M with the given input w.
If the machine M halts, we know the machine halts.
But if the machine doesnt halt in a reasonable amount of time, we cannot conclude that it wont halt. May be
we didnt wait long enough. What we need is an algorithm that can determine the correct answer for any M and
w by performing some analysis on the machines description and the input. But, we will show that no such
algorithm exists.
Let us see first, proof devised by Alan Turing (1936) that halting problem is unsolvable.
Definition 1.1: Let WM be a string that describes a Turing machine M = (Q, , , , q0, F), and let w be a
string in *. We will assume that WM and w are encoded as a string of 0s and 1s. A solution of the halting
problem is a Turing machine H, which for any WM and w, performs the computation q0 WM w * x1 qy x2
if M applied to w halts, and q0 WM w * y1 qn y2 if M applied to w does not halt. Here qy and qn are both
final states of H.
Theorem 1.1: There does not exist any Turing machine H that behaves as required by Definition 1.1. The
halting problem is therefore undecidable.
Proof: We provide proof by contradiction. Let us assume that there exists an algorithm, and consequently some
Turing machine H, that solves the haltingproblem. The input to H will be the string WM w. The requirement is
then that, the Turing machine H will halt with either a yes or no answer. We capture this by asking that H will

For More Solutions Contact To Mr. Bilal Ali : Brain Caf Computer Classes, Near U.P.
Tech. Chowk Lucknow. Contact Number:+91 9984736691,+91 9450148850
E_Mail_ID- belaal.ali@gmail.com@gmail.com, FB Page- facebook.com/bilalali0786 28
MCS-031

halt in one of two corresponding final states, say, qy or qn . We want H to operate according to the following
rules:
q0 WM w *
M x1 qy x2 if M applied to w halts, and
q0 WM w *
M y1 qn y2 if M applied to w does not halt.
This situation can also be visualized by a block diagram given below:

Next, we modify H to produce H1 such that


If H says that it will halt then H1 itself would loop
If H says that H will not halt then H1 will halt.
We can achieve this by adding two more states say, q1 and q2. Transitions are defined from qy to q1, from q1 to
q2 and from q2 to q1, regardless of the tape symbol, in such a way that the tape remains unchanged. This is
shown by another block diagram given below.

For More Solutions Contact To Mr. Bilal Ali : Brain Caf Computer Classes, Near U.P.
Tech. Chowk Lucknow. Contact Number:+91 9984736691,+91 9450148850
E_Mail_ID- belaal.ali@gmail.com@gmail.com, FB Page- facebook.com/bilalali0786 29
MCS-031

For More Solutions Contact To Mr. Bilal Ali : Brain Caf Computer Classes, Near U.P.
Tech. Chowk Lucknow. Contact Number:+91 9984736691,+91 9450148850
E_Mail_ID- belaal.ali@gmail.com@gmail.com, FB Page- facebook.com/bilalali0786 30
MCS-031

(v) Reduction of a problem for determ ining decidability : In computability theory and computational
complexity theory, a reduction is an algorithm for transforming one problem into another problem. A reduction
from one problem to another may be used to show that the second problem is at least as difficult as the first. The
mathematical structure generated on a set of problems by the reductions of a particular type generally forms a
preorder, whose equivalence classes may be used to define degrees of unsolvability and complexity classes.
Intuitively, problem A is reducible to problem B if an algorithm for solving problem B efficiently (if it
existed) could also be used as a subroutine to solve problem A efficiently. When this is true, solving A cannot
be harder than solving B. We write A m B, usually with a subscript on the to indicate the type of reduction
being used (m : mapping reduction, p : polynomial reduction)

Example of a reduction from the boolean satisfiability problem (A B) (A B C) (A B C) to a


vertex cover problem. The blue vertices form a minimum vertex cover, and the blue vertices in the gray oval
correspond to a satisfying truth assignment for the original formula.
(vi) Rice theorem: Rice's theorem: Any nontrivial property about the language recognized by a Turing
machine is undecidable. A property about Turing machines can be represented as the language of all Turing
machines, encoded as strings, that satisfy that property. The property P is about the language recognized by
Turing machines if whenever L(M)=L(N) then P contains (the encoding of) M iff it contains (the encoding of)
N. The property is non-trivial if there is at least one Turing machine that has the property, and at least one that
hasn't.
Proof: Without limitation of generality we may assume that a Turing machine that recognizes the empty
language does not have the property P. For if it does, just take the complement of P. The undecidability of that
complement would immediately imply the undecidability of P.
In order to arrive at a contradiction, suppose P is decidable, i.e. there is a halting Turning machine B that
recognizes the descriptions of Turing machines that satisfy P. Using B we can construct a Turning machine A

For More Solutions Contact To Mr. Bilal Ali : Brain Caf Computer Classes, Near U.P.
Tech. Chowk Lucknow. Contact Number:+91 9984736691,+91 9450148850
E_Mail_ID- belaal.ali@gmail.com@gmail.com, FB Page- facebook.com/bilalali0786 31
MCS-031

that accepts the language {(M,w)| M is the description of a Turing machine that accepts the string w}. As the
latter problem is undecidable this will show that B cannot exists and P must be undecidable as well.
Let MP be a Turing machine that satisfies P (as P is non-trivial there must be one). Now A operates as follows:
On input (M,w), create a (description of a) Turing machine C(M,w) as follows:
On input x, let the Turing machine M run on the string w until it accepts (so if it doesn't accept C(M,w) will run
forever).
Next run MP on x. Accept iff MP does.
Note that C(M,w) accepts the same language as MP if M accepts w; C(M,w) accepts the empty language if M
does not accept w.
Thus if M accepts w the Turing machine C(M,w) has the property P, and otherwise it doesn't.
Feed the description of C(M,w) to B. If B accepts, accept the input (M,w); if B rejects, reject.

(vii) Post correspondence problem: Undecidable problems arise in language theory also. It is required to
develop techniques for proving particular problems undecidable. In 1946, Emil Post proved that the following
problem is undecidable:
Let be an alphabet, and let L and M be two lists of nonempty strings over , such
that L and M have the same number of strings. We can represent L and M as follows:
L = ( w1, w2, w3, ..., wk )
M = ( v1, v2, v3, ..., vk )
Does there exist a sequence of one or more integers, which we represent as
( i, j, k, ..., m), that meet the following requirements:
Each of the integers is greater than or equal to one.
Each of the integers is less than or equal to k. (Recall that each list has k
strings).
The concatenation of wi, wj, wk, ..., wm is equal to the concatenation of
vi, vj, vk, ..., vm.
If there exists the sequence (i, j, k, ..., m) satisfying above conditions then
(i, j, k, ..., m) is a solution of PCP.
Let us consider some examples.
Example 3: Consider the following instance of the PCP:

For More Solutions Contact To Mr. Bilal Ali : Brain Caf Computer Classes, Near U.P.
Tech. Chowk Lucknow. Contact Number:+91 9984736691,+91 9450148850
E_Mail_ID- belaal.ali@gmail.com@gmail.com, FB Page- facebook.com/bilalali0786 32
MCS-031

Alphabet = { a, b }
List L = (a, ab)
List M = (aa, b)
We see that ( 1, 2 ) is a sequence of integers that solves this PCP instance, since the
concatenation of a and ab is equal to the concatenation of aa and b
(i.e ,w1 w2 = v1 v2 = aab). Other solutions include: ( 1, 2, 1, 2 ) , ( 1, 2, 1, 2, 1, 2 )
and so on.
(viii) NP-complete problem : A Problem P or equivalently its language L is said to be NP-complete if the
following two conditions are satisfied:
(i) The problem L2 is in the class NP (ii) For any problem L2 in NP, there is a polynomial-time reduction of L1
to L2. In this context, we introduce below another closely related and useful concept. In general, the process of
establishing a problem as NP-Complete is a two-step process. The first step, which in most of the cases is quite
simple, constitutes of guessing possible solutions of the instances, one instance at a time, of the problem and
then verifying whether the guess actually is a solution or not.
The second step involves designing a polynomial-time algorithm which reduces instances of an already
known NP-Complete problem to instances of the problem, which is intended to be shown as NP-Complete.
However, to begin with, there is a major hurdle in execution of the second step. The above technique of
reduction can not be applied unless we already have established at least one problem as NP-Complete.
Therefore, for the first NP-Complete problem, the NP-Completeness has to be established in a different manner.
As mentioned earlier, Stephen Cook (1971) established Satisfiability as the first NP-Complete problem.
The proof was based on explicit reduction of the language of any non-deterministic, polynomial-time TM to the
satisfiability problem. The proof of Satisfiability problem as the first NP-Complete problem, is quite lengthy
and we skip the proof. Interested readers may consult any of the text given in the reference Assuming the
satisfiality problem as NP-complete, the rest of the problems that we establish as NP-complete, are established
by reduction method as explained above. A diagrammatic notation of the form.

For More Solutions Contact To Mr. Bilal Ali : Brain Caf Computer Classes, Near U.P.
Tech. Chowk Lucknow. Contact Number:+91 9984736691,+91 9450148850
E_Mail_ID- belaal.ali@gmail.com@gmail.com, FB Page- facebook.com/bilalali0786 33
MCS-031

Indicates: Assuming P is already established as NP-Complete, the NP-Completeness of Q is established by


through a polynomial-time reduction from P to Q. A scheme for establishing NP-Completeness of some the
problems mentioned given below Figure:

For More Solutions Contact To Mr. Bilal Ali : Brain Caf Computer Classes, Near U.P.
Tech. Chowk Lucknow. Contact Number:+91 9984736691,+91 9450148850
E_Mail_ID- belaal.ali@gmail.com@gmail.com, FB Page- facebook.com/bilalali0786 34

Vous aimerez peut-être aussi