Vous êtes sur la page 1sur 8

III MCA / II M.Sc.

(Computer Science)

2016-18 Batch

Assignment Questions

Unit - I

1. When does this loop terminate?

for(i=0;i<12;i--)

Printf(“%d”, a[i]);

2 . Find out the number of executions of this loop

i=12;

While(i>1)

Printf(“%d”, i);

3. There are two functions f(n) and g(n) which work on a set of inputs. At some point with
some constant g(n) dominates f(n) and with some other constant, g(n) lies below the f(n).
What do you say about g(n)? Justify your answer.

4. Analyze the following block of code and bring out the complexity.

while k from 0 to n-1

while j from 0 to m-1

read m[k][j]

end for

end for

5. Inserting an element into an existing array is an O(n) operation in Array and O(1)
operation in Linked List. Why? Use the following input to justify youranswer :
98,65,57,42,29. insert: 38

1
Unit – II

1. 77,27,57,87,97,67,7 be the input array, by considering 77 as sorted, where does 27


be inserted if insertion sort is used on the array?

Insertion sort compares the first two elements.77 is in sorted sub-list.

77 27 57 87 97 67 7

Insertion sort moves ahead and compares 77 with 27.And finds that 77 is not in
correct position.It swaps 77 with 27

27 77 57 87 97 67 7

It swaps 77 with 27. Also it checks with all the elements of sorted sublist. Here we
see that sorted sub-list has only one element 27 and 77 is greater than 27. Hence
sorted sub-list remain sorted after swapping.

2. Analyze the code and state the time complexity.


Minpos=start
For(i=start+1;i<n;i++)
If(a[i]<a[minpos])
Minpos=a[i]
Swap(A,start,minpos)

3. Complete the next step.

43 32 22 13 63 57 91 78

Pivot L U

2
4. Find whether value ‘k’ is present in a collection of values ’A’, where ‘A’ is unsorted by
writing the algorithm and analyze the same.

5. How the Tony Hoar’s actual partitioning method differs from the regular quick sort?
Show the difference using the elements 1456,1872,2145,2654,3000,3710,4005.

Unit – III

1. The graph G has n nodes and n edges (there is a cycle in the graph). The cost of the
cycle is -4. What suggestion you make to calculate a shortest path between one
vertex to an another vertex in that graph?

2. Which exploration technique helps in the following? The neighbours are identified in
time proportional to the neighbours of that node.

3. Draw an adjacency matrix for the following graph.

3
4. Lavanya has to complete 12 courses for her degree. There are six compulsory
courses: Basic and Advanced Mathematics, Basic and Advanced Physics and Basic
and Advanced Electronics. She also has to complete six Optional Courses. Each
course takes one semester to complete. There are some constraints because of
prerequisites.

For Mathematics, Physics and Electronics, the Basic course must be completed
before starting the Advanced course.

Advanced Physics must be completed before starting Basic Electronics.


Advanced Mathematics must be completed before starting Advanced Physics.

The Optional Courses can be done in any order, but no more than two Optional
Courses can be taken in a semester.

5. Perform BFS using Queue on the following graph

4
5
Unit – IV

1. Which graph does not have this property? If we start at one vertex and follow the
directed edges and come back to the start vertex.

2. As per the definition of Divide and Conquer, a particular technique is used to solve
the sub-problems which are of same type. But, for all problems it is not possible to
find sub-problems. What is this technique?

3. Observe the changes that take place when adding an edge from j-k, to the given
tree

4. Topologically order the following activities shown in the graph.

5. Dijkstra’s single source shortest path algorithm when run from vertex a in the below
graph, computes the correct shortest path distance of which vertex / vertices?

Unit – V
6
1. In computer science, in order to understand the problems for which solutions are not
there, the problems are divided into classes. What are these classes are known as?

2. For a given problem P, let us assume we have given some algorithm for solving it. The
process of solving a given decision problem in the form of an algorithm is what?

3. Imagine there are two problems A and B, b is said to have an efficient algorithm so that A
is reduced to B. In another case, both A and B are not known to have efficient algorithms,
now also A reduced to B. What is your comment about the solutions we get from these two
reductions? Justify your answer

4. Explore the minimum cost spanning tree by ordering the edges in ascending order with a
suitable algorithm.

5. An undirected graph G(V, E) contains n ( n > 2 ) nodes named v1 , v2 ,….vn. Two nodes
vi , vj are connected if and only if 0 < |i – j| <= 2. Each edge (vi, vj ) is assigned a weight i
+ j. A sample graph with n = 4 is shown below. What will be the cost of the minimum cost
spanning tree of such a graph with n nodes?

weight of MST being formed


7
For n=3 (1+2+3)+(1) For n=3 (1+2+3)+(1)
For n=4 (1+2+3+4)+(1+2) For n=4 (1+2+3+4)+(1+2)
For n=5 (1+2+3+4+5)+(1+2+3) For n=5 (1+2+3+4+5)+(1+2+3)
These can be obtained by drawing graphs for these graphs. These can be
obtained by drawing graphs for these graphs.
∴ Total weight of MST is ∑ni=1i+∑n−2i=1i=n2−n+1

Vous aimerez peut-être aussi