DAA Assignment

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 18

Nagar YuwakShikshanSanstha’s

YeshwantraoChavan College of Engineering


(An Autonomous Institution affiliated to RashtrasantTukadoji Maharaj Nagpur University)
(Accredited 'A++' Grade by NAAC)
Hingna Road, Wanadongri, Nagpur - 441 110
Ph.: 07104-295083, 295085, Website: www.ycce.edu

Department of Information Technology


GROUP ASSIGNMENT 2
SOLVE ANY 10 QUESTION
SUB: DAA 6TH SEM SUBMISSION DATE: 27-04-24

Unit No 1
1.Solve following recurrence using master method.

T(n)  2Tn/2 n
T(n) 2
 4Tn/2  n
Solution :
T(n)=2T(n/2) + n T(n)=4T(n/2) + n2
Compare with T(n) = aT(n/b) + f(n) Compare with T(n) = aT(n/b) + f(n)
a=2 , b=2 , f(n) = n a=4 , b=2 , f(n) = n2 , k=2 , p=0
log ba = log 2 2 = 1 a=bk -> 4=22
f(n)= n since, p > -1
Ω(nlog b a+ ε)= Ω(n1+1)= Ω(n2) then, T(n) = θ (nlogba.logp+1n)
f(n)> Ω(nlog b a+ ε) and log ba = log 2 4 = 2
af(n/b) = 2f(n/2)
cf(n) T(n) = θ (n2.log1n)
af(n/2)<cf(n)…… is true
therefore case 3 is applied
T(n) = θ(f(n))
i.e. T(n) = θ(n)

2.Differentiate between following

a. Greedy & dynamic programming.

Greedy programming Dynamic programming


1. In a greedy algorithm, we make 1. In Dynamic Programming we make
whatever choice seems best at the decision at each step considering
moment in the hope that it will lead current problem and solution to
to global optimal solution. previously solved sub problem to
2. In Greedy Method, sometimes there calculate optimal solution .
is no such guarantee of getting 2. It is guaranteed that Dynamic
Nagar YuwakShikshanSanstha’s
YeshwantraoChavan College of Engineering
(An Autonomous Institution affiliated to RashtrasantTukadoji Maharaj Nagpur University)
(Accredited 'A++' Grade by NAAC)
Hingna Road, Wanadongri, Nagpur - 441 110
Ph.: 07104-295083, 295085, Website: www.ycce.edu

Department of Information Technology


GROUP ASSIGNMENT 2
SOLVE ANY 10 QUESTION
SUB: DAA 6TH SEM SUBMISSION DATE: 27-04-24
Optimal Solution. Programming will generate an
3. A greedy method follows the problem optimal solution as it generally
solving heuristic of making the considers all possible cases and then
locally optimal choice at each stage. choose the best.
4. It is more efficient in terms of 3. A Dynamic programming is an
memory as it never look back or algorithmic technique which is
revise previous choices. usually based on a recurrent formula
5. Greedy methods are generally faster. that uses some previously calculated
For example, dijkstra’s shortest states.
path algorithm takes O(ELogV + 4. It requires Dynamic Programming
VLogV) time. table for Memoization and it
6. The greedy method computes its increases it’s memory complexity.
solution by making its choices in a 5. Dynamic Programming is generally
serial forward fashion, never looking slower. For example, Bellman Ford
back or revising previous choices. algorithm takes O(VE) time.
7. Fractional knapsack . 6. Dynamic programming computes its
solution bottom up or top down by
synthesizing them from smaller
optimal sub solutions.
7. 0/1 knapsack problem

b. Homogeneous & nonhomogeneous recurrences.

Homogeneous recurrence Non-homogeneous recurrences.


1. A homogeneous recurrence relation is 1. A nonhomogeneous recurrence
one where the right-hand side of the relation is one where the right-hand
recurrence equation is zero. In other side of the recurrence equation is
words, it's a recurrence relation of the non-zero, i.e., there is an additional
form 𝑓(𝑛)=𝑎1𝑓(𝑛−1)+𝑎2𝑓(𝑛−2)+ function or term on the right side of
the equation. It is of the form
…+𝑎𝑘𝑓(𝑛−𝑘)f(n)=a1f(n−1)+a2
𝑓(𝑛)=𝑔(𝑛)
f(n−2)+…+akf(n−k), where 𝑎1,𝑎2,
+𝑎1𝑓(𝑛−1)+𝑎2𝑓(𝑛−2)+…
…,𝑎𝑘a1,a2,…,ak are constants and
+𝑎𝑘𝑓(𝑛−𝑘)f(n)=g(n)+a1
𝑘k is a positive integer, and 𝑓(𝑛)f(n)
is the function being defined
f(n−1)+a2f(n−2)+…+akf(n−k),
recursively. where 𝑔(𝑛)g(n) is a non-zero
2. The solutions to homogeneous function.
recurrence relations typically involve 2. The solutions to nonhomogeneous
Nagar YuwakShikshanSanstha’s
YeshwantraoChavan College of Engineering
(An Autonomous Institution affiliated to RashtrasantTukadoji Maharaj Nagpur University)
(Accredited 'A++' Grade by NAAC)
Hingna Road, Wanadongri, Nagpur - 441 110
Ph.: 07104-295083, 295085, Website: www.ycce.edu

Department of Information Technology


GROUP ASSIGNMENT 2
SOLVE ANY 10 QUESTION
SUB: DAA 6TH SEM SUBMISSION DATE: 27-04-24
finding the roots of the characteristic recurrence relations involve solving
equation associated with the both the homogeneous part and a
recurrence. particular solution for the
3. The general solution to a nonhomogeneous part.
homogeneous recurrence relation 3. Methods like the method of
consists of a linear combination of undetermined coefficients or the
functions based on the roots of the method of variation of parameters are
characteristic equation. often used to find particular solutions
for nonhomogeneous recurrences.

3. Solve following recurrence using master method.

T(n)  2Tn/2 n2
T(n)  2Tn/2  nlogn
Solution:
T(n) = 2T(n/2) + n2 T(n) = 2T(n/2) + nlogn
Compare with T(n) = aT(n/b) + f(n) Compare with T(n) = aT(n/b) + f(n)
a=2 , b=2 , f(n) = n2 , k=2 , p=0 a=2 , b=2 , f(n) = nlogn , k=1 , p=1
a<bk -> 2<22 bk=21=2
case 3 is applied a=bk
since, p >=0 case 2 is applied
then T(n) = θ (nklogpn) since p>-1
log ba = log 2 2 = 1 then T(n) = θ (nlogba.logp+1n)
therefore T(n) = θ (n2log0n) log ba = log 2 2 = 1
T(n) = θ (n2) therefore, T(n) = θ (n1.log1+1n)
i.e. T(n) = θ (n1.log2n)

Unit No 2

1.Explain Asymptotic notation & calculate upper, lower & tight bound of following.
Nagar YuwakShikshanSanstha’s
YeshwantraoChavan College of Engineering
(An Autonomous Institution affiliated to RashtrasantTukadoji Maharaj Nagpur University)
(Accredited 'A++' Grade by NAAC)
Hingna Road, Wanadongri, Nagpur - 441 110
Ph.: 07104-295083, 295085, Website: www.ycce.edu

Department of Information Technology


GROUP ASSIGNMENT 2
SOLVE ANY 10 QUESTION
SUB: DAA 6TH SEM SUBMISSION DATE: 27-04-24
3n
a) 6 5
b) 2002

Solution:
 Asymptotic Notations are mathematical tools used to analyze the performance of
algorithms by understanding how their efficiency changes as the input size grows.
 These notations provide a concise way to express the behavior of an algorithm’s time
or space complexity as the input size approaches infinity.
 Rather than comparing algorithms directly, asymptotic analysis focuses on
understanding the relative growth rates of algorithms’ complexities.
 It enables comparisons of algorithms’ efficiency by abstracting away machine-
specific constants and implementation details, focusing instead on fundamental
trends.
 Asymptotic analysis allows for the comparison of algorithms’ space and time
complexities by examining their performance characteristics as the input size varies.
 By using asymptotic notations, such as Big O, Big Omega, and Big Theta, we can
categorize algorithms based on their worst-case, best-case, or average-case time or
space complexities, providing valuable insights into their efficiency.

2.How Does Amortized Complexity Occur? Describe a specific amortized analysis


method.
Solution:

 Amortized analysis is a technique used in computer science to analyze the average-


case time complexity of algorithms that perform a sequence of operations, where
some operations may be more expensive than others. The idea is to spread the cost of
these expensive operations over multiple operations, so that the average cost of each
operation is constant or less.
 For example, consider the dynamic array data structure that can grow or shrink
dynamically as elements are added or removed. The cost of growing the array is
proportional to the size of the array, which can be expensive. However, if we amortize
the cost of growing the array over several insertions, the average cost of each
insertion becomes constant or less.
Nagar YuwakShikshanSanstha’s
YeshwantraoChavan College of Engineering
(An Autonomous Institution affiliated to RashtrasantTukadoji Maharaj Nagpur University)
(Accredited 'A++' Grade by NAAC)
Hingna Road, Wanadongri, Nagpur - 441 110
Ph.: 07104-295083, 295085, Website: www.ycce.edu

Department of Information Technology


GROUP ASSIGNMENT 2
SOLVE ANY 10 QUESTION
SUB: DAA 6TH SEM SUBMISSION DATE: 27-04-24
 Amortized analysis provides a useful way to analyze algorithms that perform a
sequence of operations where some operations are more expensive than others, as it
provides a guaranteed upper bound on the average time complexity of each operation,
rather than the worst-case time complexity.
Aggregate analysis method-

In aggregate analysis, there are two steps. First, we must show that a sequence
of 𝑛n operations takes 𝑇(𝑛)T(n) time in the worst case. Then, we show that each
operation takes 𝑇(𝑛)𝑛nT(n) time, on average. Therefore, in aggregate analysis, each
operation has the same cost. In the previous example of cake-making, both operations
would be described as medium, instead of fast and slow.

A common example of aggregate analysis is a modified stack. Stacks are a linear data
structure that have two constant-time operations. push(element) puts an element on the
top of the stack, and pop() takes the top element off of the stack and returns it. These
operations are both constant-time, so a total of 𝑛n operations (in any order) will result
in 𝑂(𝑛)O(n) total time.

Now, a new operation is added to the stack. multipop(k) will either pop the
top 𝑘k elements in the stack, or if it runs out of elements before that, it will pop all of the
elements in the stack and stop. The pseudo-code for multipop(k) would look like this:

multipop(k):
while stack not empty and k > 0:
k = k - 1
stack.pop()
Looking at the pseudo-code, it's easy to see that this is not a constant-time
operation. multipop can run for at most 𝑛n times, where 𝑛n is the size of the stack. So,
the worst-case runtime for multipop is 𝑂(𝑛)O(n). So, in atypical analysis, that means
that 𝑛n multipop operations take 𝑂(𝑛2)O(n2) time.

However, that's not actually the case. Think about multipop and what it's actually
doing. multipop cannot function unless there's been a push to the stack because it
would have nothing to pop off. In fact, any sequence of 𝑛n operations
of multipop , pop and push can take at most 𝑂(𝑛)O(n) time. multipop , the only non-
Nagar YuwakShikshanSanstha’s
YeshwantraoChavan College of Engineering
(An Autonomous Institution affiliated to RashtrasantTukadoji Maharaj Nagpur University)
(Accredited 'A++' Grade by NAAC)
Hingna Road, Wanadongri, Nagpur - 441 110
Ph.: 07104-295083, 295085, Website: www.ycce.edu

Department of Information Technology


GROUP ASSIGNMENT 2
SOLVE ANY 10 QUESTION
SUB: DAA 6TH SEM SUBMISSION DATE: 27-04-24
constant-time operation in this stack, can only take 𝑂(𝑛)O(n) time if there have also
been 𝑛n constant-time push operations on the stack. In the very worst case, there
are 𝑛n constant-time operations and just 1 operation taking 𝑂(𝑛)O(n) time.

For any value of 𝑛n, any sequence of multipop , pop , and push takes 𝑂(𝑛)O(n) time.
So, using aggregate analysis,

𝑇(𝑛)𝑛=𝑂(𝑛)𝑛=𝑂(1).nT(n)=nO(n)=O(1).
So, this stack has an amortized cost of 𝑂(1)O(1) per operation.

3. What is the time complexity of the following code :

1)void fun(int n)
{
if (n < 5)
cout << "ycce";
else {
for (int i = 0; i < n; i++) {
cout << i;
}
}
}
Solution: The time complexity of above code is O(n) as the loop will run for n times.

2) void fun(int n)
{
for (int i = 0; i <= n / 3; i++)

for (int j = 1; j <= n; j = j + 4)

cout << "ycce";

Solution: The time complexity for above code is O(n) as the for loop runs for n times.
Nagar YuwakShikshanSanstha’s
YeshwantraoChavan College of Engineering
(An Autonomous Institution affiliated to RashtrasantTukadoji Maharaj Nagpur University)
(Accredited 'A++' Grade by NAAC)
Hingna Road, Wanadongri, Nagpur - 441 110
Ph.: 07104-295083, 295085, Website: www.ycce.edu

Department of Information Technology


GROUP ASSIGNMENT 2
SOLVE ANY 10 QUESTION
SUB: DAA 6TH SEM SUBMISSION DATE: 27-04-24

4. What is Amortized Complexity? Explain any one methods of Amortized Analysis.

Solution:

The complexity of a method or operation, as defined in Chapter 2 of the text, is the actual
complexity of the method/operation. The actual complexity of an operation is determined by
the step count for that operation, and the actual complexity of a sequence of operations is
determined by the step count for that sequence. The actual complexity of a sequence of
operations may be determined by adding together the step counts for the individual
operations in the sequence. Typically, determining the step count for each operation in the
sequence is quite difficult, and instead, we obtain an upper bound on the step count for the
sequence by adding together the worst-case step count for each operation.

Accounting Method
When we use the accounting method, we must first assign an amortized cost for each month
and then show that this assignment satisifes Equation (3). We have the option to assign a
different amortized cost to each month. In our maintenance contract example, we know the
actual cost by month and could use this actual cost as the amortized cost. It is, however,
easier to work with an equal cost assignment for each month. Later, we shall see examples of
operation sequences that consist of two or more types of operations (for example, when
dealing with lists of elements, the operation sequence may be made up of search, insert, and
remove operations). When dealing with such sequences we often assign a deifferent
amortized cost to operations of different types (however, operations of the same type have the
same amortized cost).

To get the best upper bound on the sum of the actual costs, we must set the amortized
monthly cost to be the smallest number for which Equation (3) is satisifed for all n. From the
above table, we see that using any cost less than $75 will result in P(n) - P(0) < 0 for
some values of n. Therefore, the smallest assignable amortized cost consistent with Equation
(3) is $75.

Generally, when the accounting method is used, we have not computed the aggregate cost.
Therefore, we would not know that $75 is the least assignable amortized cost. So we start by
assigning an amortized cost (obtained by making an educated guess) to each of the different
operation types and then proceed to show that this assignment of amortized costs satisfies
Equation (3). Once we have shown this, we can obtain an upper bound on the cost of any
Nagar YuwakShikshanSanstha’s
YeshwantraoChavan College of Engineering
(An Autonomous Institution affiliated to RashtrasantTukadoji Maharaj Nagpur University)
(Accredited 'A++' Grade by NAAC)
Hingna Road, Wanadongri, Nagpur - 441 110
Ph.: 07104-295083, 295085, Website: www.ycce.edu

Department of Information Technology


GROUP ASSIGNMENT 2
SOLVE ANY 10 QUESTION
SUB: DAA 6TH SEM SUBMISSION DATE: 27-04-24
operation sequence by computing

sum1 <= i <= k f(i) * amortized(i)

where k is the number of different operation types and f(i) is the frequency of operation
type i (i.e., the number of times operations of this type occur in the operation sequence).

For our maintenance contract example, we might try an amortized cost of $70. When we use
this amortized cost, we discover that Equation (3) is not satisifed for n = 12 (for example)
and so $70 is an invalid amortized cost assignment. We might next try $80. By constructing
a table such as the one above, we will observe that Equation (3) is satisfied for all months in
the first 12 month cycle, and then conclude that the equation is satisifed for all n. Now, we
can use $80n as an upper bound on the contract cost for n months.

Unit No 4

1. Generate the optimum sequence for the multiplication of the following matrices
and find the number of operations required for the multiplication.
A= 13 * 5
B= 5 * 89
C= 89 * 3
D= 3 * 34
Solution:
Nagar YuwakShikshanSanstha’s
YeshwantraoChavan College of Engineering
(An Autonomous Institution affiliated to RashtrasantTukadoji Maharaj Nagpur University)
(Accredited 'A++' Grade by NAAC)
Hingna Road, Wanadongri, Nagpur - 441 110
Ph.: 07104-295083, 295085, Website: www.ycce.edu

Department of Information Technology


GROUP ASSIGNMENT 2
SOLVE ANY 10 QUESTION
SUB: DAA 6TH SEM SUBMISSION DATE: 27-04-24
Nagar YuwakShikshanSanstha’s
YeshwantraoChavan College of Engineering
(An Autonomous Institution affiliated to RashtrasantTukadoji Maharaj Nagpur University)
(Accredited 'A++' Grade by NAAC)
Hingna Road, Wanadongri, Nagpur - 441 110
Ph.: 07104-295083, 295085, Website: www.ycce.edu

Department of Information Technology


GROUP ASSIGNMENT 2
SOLVE ANY 10 QUESTION
SUB: DAA 6TH SEM SUBMISSION DATE: 27-04-24
Nagar YuwakShikshanSanstha’s
YeshwantraoChavan College of Engineering
(An Autonomous Institution affiliated to RashtrasantTukadoji Maharaj Nagpur University)
(Accredited 'A++' Grade by NAAC)
Hingna Road, Wanadongri, Nagpur - 441 110
Ph.: 07104-295083, 295085, Website: www.ycce.edu

Department of Information Technology


GROUP ASSIGNMENT 2
SOLVE ANY 10 QUESTION
SUB: DAA 6TH SEM SUBMISSION DATE: 27-04-24
Nagar YuwakShikshanSanstha’s
YeshwantraoChavan College of Engineering
(An Autonomous Institution affiliated to RashtrasantTukadoji Maharaj Nagpur University)
(Accredited 'A++' Grade by NAAC)
Hingna Road, Wanadongri, Nagpur - 441 110
Ph.: 07104-295083, 295085, Website: www.ycce.edu

Department of Information Technology


GROUP ASSIGNMENT 2
SOLVE ANY 10 QUESTION
SUB: DAA 6TH SEM SUBMISSION DATE: 27-04-24

Unit No 5

1. What is a graph coloring problem? Explain it with suitable real-world example.

Solution:
 The graph coloring problem entails assigning colours to specific elements of a graph
while adhering to particular limits and constraints. In other terms, Graph coloring
refers to the act of assigning colours to vertices so that no two neighbouring vertexes
have the same colour.
 No two nearby vertices, adjacent edges, or adjacent areas in a graph are coloured with
the same number of colours. This is known as the chromatic number, and the graph is
known as a properly coloured graph.
 Colours, order of coloring, colour assignment, and other constraints are established on
the graph while graph coloring. A Color is assigned to a vertex or a specific region.
As a result, vertices or areas with the same colour create independent sets.

EXAM SCHEDULING
Let’s suppose algebra, physics, statistics and calculus are four courses of study in our
college. And let’s say that following pairs have common students :
1. Algebra and statistics
2. Algebra and calculus
3. Statistics and physics
Problem: Say algebra and statistics exam is held on same day then students taking both
courses have to miss at least one exam. They can’t take both at same time. How do we
schedule exams in minimum no of days so that courses having common students are not held
on same day?
Nagar YuwakShikshanSanstha’s
YeshwantraoChavan College of Engineering
(An Autonomous Institution affiliated to RashtrasantTukadoji Maharaj Nagpur University)
(Accredited 'A++' Grade by NAAC)
Hingna Road, Wanadongri, Nagpur - 441 110
Ph.: 07104-295083, 295085, Website: www.ycce.edu

Department of Information Technology


GROUP ASSIGNMENT 2
SOLVE ANY 10 QUESTION
SUB: DAA 6TH SEM SUBMISSION DATE: 27-04-24
Solution: Graph coloring.
First draw a graph with courses as vertex and they are connected by edges if they have
common students. Second color the graph such that no two adjacent vertices are assigned the
same color as shown below:

 Look at the above graph. It solves our problem. We can conduct exam of courses on
same day if they have same color.
 Our solution:
DAY 1: Algebra and Physics
DAY 2: Statistics and Calculus
 This solves our problem of scheduling exams so that all students can take exams
without worrying about missing one.
Nagar YuwakShikshanSanstha’s
YeshwantraoChavan College of Engineering
(An Autonomous Institution affiliated to RashtrasantTukadoji Maharaj Nagpur University)
(Accredited 'A++' Grade by NAAC)
Hingna Road, Wanadongri, Nagpur - 441 110
Ph.: 07104-295083, 295085, Website: www.ycce.edu

Department of Information Technology


GROUP ASSIGNMENT 2
SOLVE ANY 10 QUESTION
SUB: DAA 6TH SEM SUBMISSION DATE: 27-04-24

2. Define Hamiltonian cycle. Find the Hamiltonian cycle for the following graph

Solution:
A Hamiltonian cycle, also called a Hamiltonian circuit is a cycle (i.e., closed loop)
through a graph that visits each node exactly once . A graph possessing a Hamiltonian
cycle is said to be a Hamiltonian graph.

a -> b -> c -> e -> f -> d -> a (cycle)


a -> c -> b -> e -> f -> d -> a (cycle)
a -> c -> d -> f -> e -> b -> a (cycle)
a -> d -> f -> e -> b -> c -> a (cycle)
a -> d -> f -> e -> c -> b -> a (cycle)
So, there are five possible Hamiltonian cycles for the given graph.
Nagar YuwakShikshanSanstha’s
YeshwantraoChavan College of Engineering
(An Autonomous Institution affiliated to RashtrasantTukadoji Maharaj Nagpur University)
(Accredited 'A++' Grade by NAAC)
Hingna Road, Wanadongri, Nagpur - 441 110
Ph.: 07104-295083, 295085, Website: www.ycce.edu

Department of Information Technology


GROUP ASSIGNMENT 2
SOLVE ANY 10 QUESTION
SUB: DAA 6TH SEM SUBMISSION DATE: 27-04-24

3. Define Hamiltonian cycle. Find the Hamiltonian cycle for the following graph

Solution :

A Hamiltonian cycle, also called a Hamiltonian circuit is a cycle (i.e., closed loop)
through a graph that visits each node exactly once . A graph possessing a Hamiltonian
cycle is said to be a Hamiltonian graph.

1 -> 2 -> 3 -> 4 -> 5 -> 1 (cycle)


1-> 5 -> 4 -> 3 -> 2 -> 1 a (cycle)
So, there are two possible Hamiltonian cycles for the given graph.
Nagar YuwakShikshanSanstha’s
YeshwantraoChavan College of Engineering
(An Autonomous Institution affiliated to RashtrasantTukadoji Maharaj Nagpur University)
(Accredited 'A++' Grade by NAAC)
Hingna Road, Wanadongri, Nagpur - 441 110
Ph.: 07104-295083, 295085, Website: www.ycce.edu

Department of Information Technology


GROUP ASSIGNMENT 2
SOLVE ANY 10 QUESTION
SUB: DAA 6TH SEM SUBMISSION DATE: 27-04-24
4. Define Hamiltonian cycle. Write the algorithm for the same & find the
Hamiltonian cycle for the following graph

Solution:
A Hamiltonian cycle, also called a Hamiltonian circuit is a cycle (i.e., closed loop)
through a graph that visits each node exactly once . A graph possessing a Hamiltonian
cycle is said to be a Hamiltonian graph.

1 -> 2 -> 8-> 7-> 6 -> 5 ->4 ->3 ->1 (cycle)


1-> 3-> 4 -> 5 -> 6 -> 7 ->8 ->2 ->1 (cycle)
So, there are two possible Hamiltonian cycles for the given graph.
Nagar YuwakShikshanSanstha’s
YeshwantraoChavan College of Engineering
(An Autonomous Institution affiliated to RashtrasantTukadoji Maharaj Nagpur University)
(Accredited 'A++' Grade by NAAC)
Hingna Road, Wanadongri, Nagpur - 441 110
Ph.: 07104-295083, 295085, Website: www.ycce.edu

Department of Information Technology


GROUP ASSIGNMENT 2
SOLVE ANY 10 QUESTION
SUB: DAA 6TH SEM SUBMISSION DATE: 27-04-24
Algorithm :

1.Start with an empty path and an empty list of visited nodes.


2.Choose a starting node (let's say node 1) and mark it as visited.
3.Explore paths from node 1 to its adjacent nodes (2, 3, and 7) that haven't been
visited yet.
4.Start with node 2: Add node 2 to the path, mark it as visited.
5.Start with node 3: Add node 3 to the path, mark it as visited.
6.Start with node 7: Add node 7 to the path, mark it as visited.
7.Repeat step 3 recursively for each adjacent node of the current node (2, 3, 7).
8.For node 2: Explore paths from node 2 to its adjacent unvisited nodes (3 and 8).

9.For node 3: Explore paths from node 3 to its adjacent unvisited nodes (4 and 6).
10.For node 7: Explore paths from node 7 to its adjacent unvisited node (8).
11.Continue exploring paths and backtracking until a Hamiltonian cycle is found or
until all paths have been explored.
12.If a Hamiltonian cycle is found, return the cycle. Otherwise, return that no
Hamiltonian cycle exists in the graph.

Unit No 6.

1. Write shorts Notes on :


Solution:
P:
 The P in the P class stands for Polynomial Time. It is the collection of decision
problems(problems with a “yes” or “no” answer) that can be solved by a deterministic
machine in polynomial time.

Features:

 The solution to P problems is easy to find.


 P is often a class of computational problems that are solvable and tractable. Tractable
means that the problems can be solved in theory as well as in practice. But the
problems that can be solved in theory but not in practice are known as intractable.

NP:
Nagar YuwakShikshanSanstha’s
YeshwantraoChavan College of Engineering
(An Autonomous Institution affiliated to RashtrasantTukadoji Maharaj Nagpur University)
(Accredited 'A++' Grade by NAAC)
Hingna Road, Wanadongri, Nagpur - 441 110
Ph.: 07104-295083, 295085, Website: www.ycce.edu

Department of Information Technology


GROUP ASSIGNMENT 2
SOLVE ANY 10 QUESTION
SUB: DAA 6TH SEM SUBMISSION DATE: 27-04-24
 The NP in NP class stands for Non-deterministic Polynomial Time. It is the collection
of decision problems that can be solved by a non-deterministic machine in polynomial
time.

Features:

 The solutions of the NP class are hard to find since they are being solved by a non-
deterministic machine but the solutions are easy to verify.
 Problems of NP can be verified by a Turing machine in polynomial time.

NP Hard:
 An NP-hard problem is at least as hard as the hardest problem in NP and it is a class
of problems such that every problem in NP reduces to NP-hard.

Features:

 All NP-hard problems are not in NP.


 It takes a long time to check them. This means if a solution for an NP-hard problem is
given then it takes a long time to check whether it is right or not.
 A problem A is in NP-hard if, for every problem L in NP, there exists a polynomial-
time reduction from L to A.

NP-Complete:
 A problem is NP-complete if it is both NP and NP-hard. NP-complete problems are
the hard problems in NP.

Features:

 NP-complete problems are special as any problem in NP class can be transformed or


reduced into NP-complete problems in polynomial time.
 If one could solve an NP-complete problem in polynomial time, then one could also
solve any NP problem in polynomial time.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy