Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
0 of .
Results for:
No results containing your search query
P. 1
MC0080 _ Analysis and Design of Algorithms Set û 1

MC0080 _ Analysis and Design of Algorithms Set û 1

Ratings: (0)|Views: 734 |Likes:
Published by rohit143rko
MAY 2011 MCA 4th Semester solved Assignments Set-1. MC0079 Computer Based Optimization Methods.
MAY 2011 MCA 4th Semester solved Assignments Set-1. MC0079 Computer Based Optimization Methods.

More info:

Categories:Topics, Art & Design
Published by: rohit143rko on Nov 23, 2011
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as DOCX, PDF, TXT or read online from Scribd
See more
See less





Semester 4 MC0080
Analysis and Design of AlgorithmsAssignment Set
1 Roll No.
MAY 2011Master of Computer Application (MCA)
Semester 4MC0080
Analysis and Design of Algorithms
4 Credits
(Book ID: B0891)Assignment Set
1 (60 Marks)Answer the following: 6
10 = 6
Explain the structure of Fibonacci heaps
?Ans 1:
A Fibonacci heap is a collection of trees satisfying the minimum-heap property, that is, the key of achild is always greater than or equal to the key of the parent. This implies that the minimum key isalways at the root of one of the trees. Compared with binomial heaps, the structure of a Fibonacciheap is more flexible. The trees do not have a prescribed shape and in the extreme case the heapcan have every element in a separate tree. This flexibility allows some operations to be executed in a"lazy" manner, postponing the work for later operations. For example merging heaps is done simplyby concatenating the two lists of trees, and operation
decrease key 
sometimes cuts a node from itsparent and forms a new tree.However at some point some order needs to be introduced to the heap to achieve the desiredrunning time. In particular, degrees of nodes (here degree means the number of children) are keptquite low: every node has degree at most
) and the size of a subtree rooted in a node of degree
is at least
+ 2
, where
is the
th Fibonacci number. This is achieved by the rule that wecan cut at most one child of each non-root node. When a second child is cut, the node itself needs tobe cut from its parent and becomes the root of a new tree (see Proof of degree bounds, below). Thenumber of trees is decreased in the operation
delete minimum
, where trees are linked together.As a result of a relaxed structure, some operations can take a long time while others are done veryquickly. In the amortized running time analysis we pretend that very fast operations take a little bitlonger than they actually do. This additional time is then later subtracted from the actual runningtime of slow operations. The amount of time saved for later use is measured at any given momentby a potential function. The potential of a Fibonacci heap is given by
Potential =
+ 2
is the number of trees in the Fibonacci heap, and
is the number of marked nodes. A nodeis marked if at least one of its children was cut since this node was made a child of another node (allroots are unmarked).
Semester 4 MC0080
Analysis and Design of AlgorithmsAssignment Set
1 Roll No.
2Thus, the root of each tree in a heap has one unit of time stored. This unit of time can be used laterto link this tree with another tree at amortized time 0. Also, each marked node has two units of timestored. One can be used to cut the node from its parent. If this happens, the node becomes a rootand the second unit of time will remain stored in it as in any other root.
2. What do you mean by reduction, NP-Complete and NP hard problem?Ans 2:Reduction
Formally, NP-completeness is defined in terms of "reduction" which is just a complicated way of saying one problem is easier than another.We say that A is easier than B, and write A < B, if we can write down an algorithm for solving A thatuses a small number of calls to a subroutine for B (with everything outside the subroutine calls beingfast, polynomial time). There are several minor variations of this definition depending on thedetailed meaning of "small" -- it may be a polynomial number of calls, a fixed constant number, or just one call.Then if A < B, and B is in P, so is A: we can write down a polynomial algorithm for A by expanding thesubroutine calls to use the fast algorithm for B.So "easier" in this context means that if one problem can be solved in polynomial time, so can theother. It is possible for the algorithms for A to be slower than those for B, even though A < B.As an example, consider the Hamiltonian cycle problem. Does a given graph have a cycle visitingeach vertex exactly once? Here's a solution, using longest path as a subroutine:
for each edge (u,v) of Gif there is a simple path of length n-1 from u to vreturn yes // path + edge form a cyclereturn no
This algorithm makes m calls to a longest path subroutine, and does O(m) work outside thosesubroutine calls, so it shows that Hamiltonian cycle < longest path. (It doesn't show that Hamiltoniancycle is in P, because we don't know how to solve the longest path subproblems quickly.)As a second example, consider a polynomial time problem such as the minimum spanning tree. Thenfor every other problem B, B < minimum spanning tree, since there is a fast algorithm for minimumspanning trees using a subroutine for B. (We don't actually have to call the subroutine, or we can callit and ignore its results.)
What is NP?
NP is the set of all decision problems (question with yes-or-no answer) for which the 'yes'-answerscan be verified in polynomial time (O(n^k) where n is the problem size, and k is a constant) by adeterministic Turing machine.Polynomial time is sometimes used as the definition o
.A decision problem is NP-complete if:
Definition of NP-completeness
is in NP, andEvery problem in NP isreducibleto in polynomial time.
Semester 4 MC0080
Analysis and Design of AlgorithmsAssignment Set
1 Roll No.
3Can be shown to be in NP by demonstrating that a candidate solution to can be verified inpolynomial time.A problem is reducible to if there is a polynomial-time many-one reduction, adeterministicalgorithmwhich transforms any instance into an instance , such that the answer to is
 if and only if the answer to is
. To prove that an NP problem is in fact an NP-completeproblem it is sufficient to show that an already known NP-complete problem reduces to .Note that a problem satisfying condition 2 is said to beNP-hard,whether or not it satisfiescondition1.A consequence of this definition is that if we had a polynomial time algorithm (on aUTM,or anyotherTuring-equivalentabstract machine)for , we could solve all problems in NP in polynomial time.
What is NP-Hard?
NP-Hard are problems that are at least as hard as the hardest problems in NP. Note that NP-Complete problems are also NP-hard. However not all NP-hard problems are NP (or even a decisionproblem), despite having 'NP' as a prefix. That is the NP in NP-hard does not mean 'non-deterministicpolynomial time'. Yes this is confusing but its usage is entrenched and unlikely to change.
3. Explain the concept of bubble sort and also write the algorithm for bubblesort.Ans 3 :
Bubble Sort
The Bubble Sort algorithm for sorting of n numbers, represented by an array
 A [1..n]
,proceeds by scanning the array from left to right. At each stage, compares
adjacent pairs
of numbers at positions
 A [i +1]
and whenever a pair of adjacent numbers is found tobe out of order, then the positions of the numbers are exchanged. The algorithm repeatsthe process for numbers at positions
 A [i + 1]
 A [i + 2]
Thus in the first pass after scanning once all the numbers in the given list, the largestnumber will reach its destination, but other numbers in the array, may not be in order. Ineach subsequent pass, one more number reaches its destination.
In the following, in each line, pairs of adjacent numbers, shown in bold, are compared. Andif the pair of numbers are not found in proper order, then the positions of these numbersare exchanged.The list to be sorted has
n = 6
as shown in the first row below:

Activity (8)

You've already reviewed this. Edit your review.
1 thousand reads
1 hundred reads
piggymiggy liked this
Amit Sharma liked this
Manish Kumar liked this
Sneha Latha liked this
Namita Kumari liked this
rohit143rko added this note
I hope this would help you folks to complete your Assignments. Please feel free to provide your valuable suggestions and comments. So, that I would try to make it more better for you guys in future Assignments.

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->