0% found this document useful (0 votes)
5 views

Algorithms

Algo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Algorithms

Algo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

DESIGN AND ANALYSIS OF ALGORITHMS

SOLUTION 2023
Group- A
(Very Short Answer Type Question)
Answer any ten of the following:
of
) State
True/False: Approximation algorithm guaranties the best quality
solution.
Chapter Name: «APPROXIMATION ALGORITHMS"
Answer: False

) State TruelFalse: O( logn) >O(n)


Chapter Name: "INTRODUCTION"
Answer: False

using Greedy method?


i) What is the time complexity of Knapsack algorithm STRATEGIES"
Chapter Name: "FUNDAMBNTAL ALGORITHMIC
Answer: O(n*logn)
are same.
iv) State True/Falsse: Adjacency matrix and Path MatrixALGORITHMS"
Chapter Name: "GRAPH AND TREE TRAVERSAL
Answer: False

Polynomial Algorithm.
v) State True/False: Ordered searching algorithm is a PROBLEMS"
Chapter Name: "TRACTABLE AND INTRACTABLE
Answer: False

quality of solution.
vi)State True/False: Brute Force method gives the bestSTRATEGIES"
ALGORITHMIC
Chapter Name: "FUNDAMENTAL
Answer: True

vi) State True/False: Travelling Salesman Problem is a Non-Polynomial problem.


INTRACTABLE PROBLEMS"
Chapter Name: "TRACTABLE AND
Answer: True

viii)Name one heuristic method of searching.


TRAVERSAL ALGORITHMS"
Chapter Name: "GRAPH AND TREE
Answer: Breadth First Search
search algorithm is
Ix) Best case time complexity of Binary
ALGORITHMIC STRATEGIES"
Chapter Name: "FUNDAMENTAL
Answer: O(1)

DAA-153
POrULAR PUBLICATIONS

) The time complexity of Floyd's algorithm is


Chapter Name: "FUNDAMENTAL ALGORITHMIC
Answer: O(n')
xi) Backtracking follows
STRATEGI
traversal technique.
ES"
Chapter Name: "FUNIDAMENTAL
ALGORITHMIC
Answer: Depth First Search
xii) What is spanning tree?
STRATEGIES"
Chapter Name: "GRAPH AND TREE
TRAVERSAL A
Answer:
Aspanning tree is a subset of Graph G,
minimum possible number of edges.
such that all the vertices
ALGORITHMS"
are
Group- B
COInecde
(Short Answer Type Question)
2. Write down an
algorithm to solve the Job Sequencing with
using Greedy method.
Answer:
What is the time
Deadline
complexity of your algorithm?
Refer to "FUNDAMENTAL ALGORITHMIC STRATEGIES";
Type Question No. 4.
3. Find the maximum flow of the
Long Atsw
following network. Mention each step clear
27 18
15

6
24
3

Chapter Name: "GRAPH AND TREE TRAVERSAL


Answer: ALGORITHMS"
0/12/18 Path Flow
4 5
7/19/27 0/12/18 -4-3-6 8
1-2-6 8
0/6 7/15 1-2-4-5-6 6
1-4-5-6 12
10/16/24
3 0/8 34 - Maximum fox
10

0/8

DAA-154
DESIGN AND ANALYSIS OL ALKORITIIMS
Write down an algorithm in Greedy method to find the maximum spanning tree
byprim's algorithm. What is the time complexity of your algorithm?
Answer:
Referrto
to "GRAPHAND TREE TRAVERSAL ALGORITHMS"; Long Answer
2.
DypeQuestion No.
theorem.
6.a)State Cook's
b)Define Clique with example.
Chapterl Name: "TRACTABLE AND INTRACTABLEPROBLEMS"
Answer:
) Refer toSlhort Answer Type Question No, 7.
Refer to Short Answer Type Question No. 3.
6. Define the following terms:
(i) Brute force algorithm
(ii) Approximation Algorithm
Answer:
STRATEGIES"; Short Answer
) Refer to "FUNDAMENTAL ALGORITHMIC
Type Question No. 20. ALGORITHMS": Long Answer Type
i) Refer to APPROXIMATION
Question No. 1(4).
Group-C
(Long Answer Type Question)
minimum spanning tree using Prim's method from the following
7. a) Find the
graph. Mention each step clearly.
28
10

14 16

7 3

24
5 18 12

N-Queens problem using backtracking.


b) Write an algorithm to find all solutions of
What is the time complexity of your algorithm?]
path using Floyd's method.
c) to find all pairs shortest
d)Write an algorithm
Answer:
TREE TRAVERSAL AL GORITHMS"; Short
AND
a) Refer to "GRAPH 3.
Answer Type Question No.
DAA-155
POrULAR PUBLICATIONS

ALGORITHMIC
b)& Refer to "FUNDAMENTAL
Answer Type Question No. 15(b).
d) Algorithm
For a graph with Nvertices:
STRATEGIES
Step 1: Initialize the shortestpaths between any 2 vertices with Infinity
vertices, then
Step 2: Find all pair shortest paths that use Ointermediate all Nvertices find fhe
using
paths that use Iintermediate vertex and so on.. until
nodes.
Minimizethe shortest paths between any 2pairs in the previous
Step 4:3: For any 2vertices (i,j),one should actually minimize the distances
Step Toperatetrieonk
pair using the first Knodes, so the shortest path will dist[i1]
be: min(o

the shortest path between the pair k,j. As the shortest path be a [k+didsistt[|\|KkIi0b)
dist[i][k] represents the shortest path that only uses the firstwillKvertices.
shortest path from i to k, then from k to j.
for (int k = 1; k <= n; k++) {
concatenation
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
dist [i) G1 = min( ist [i] [jl, dist [i][k] +
dist (ki51
)

8. a) Write down an algorithm of Quick Sort.


b) Derive the best, worst and average case time complexity of your algorithm
Answer:
Refer to "FUNDAMENTAL ALGORITHMIC STRATEGIES",
Type Question No. 11. Long Ase
9. a) Find the minimum number of scalar operation needed to multiply the
A1, A2, A3 and A4 having dimensions 30×35, 35x15, 15x5 and 5x10 matita
Chapter Name: MISCELLANEOUS"
Answer:
respectively.
The answer is 9375
Matrix Parenthesizing willbe Al(A2A3)A4) for minimum number ofscalar
multiplications
it willsolve by using dynamic programming as
Dimensions of given matrix is :
Al (30×35), A2 (35x15), A3 (15x5)and A4 (5x10)
A12=30x35x15=15750
A23=35x15x5=2625
A34=15x5x 10=750
A13 = min (A12 + A33 +35x15x5 = 18375, Al1 + A23 + 30x35x5=9375)
A24= min (A23 +A44 +5x10x5 =9375, A22+ A34 +5x20x5= 6776)
DAA-156
ALGORTHMS
DESIGNAND ANALYSISOF

min (All+ A24 +10x$*5, A12 +A34 + 10×20x$> 6736, A13 +A44
Ox20×5)
spanning tree
Write
down an algorithm using Greedy method to find minimum
by
) Krushkal'salgorithm.
Answer: Long Answer
RefertoGRAPH AND TREE TRAVERSAL ALGORITH
ipe Question No. 8(c).
c)
Findthe time complexity of your algorithm.
Answer:
ALGORITHMS"; Long Answer
AND
Referto "GRAPH 7. TREE TRAVERSAL
No.
TypeQuestion
Bound.
Differentiate between Backtracking and Branch and STRATEGIES"
d)
Chapter Name: FUNDAMENTAL ALGORITHMIC
Answer:
Backtracking Branch and Bound
Parameter solve
find alllBranch-and-Bound is used to
Approach Backtracking is used to problems. When it
possible solutions available to aloptimisation
that it already has a better
problem. When it realises that itl realises solution that the pre-solution
|has made a bad choice, it undoesoptimal
to, it abandons that pre-solution.
the last choice by backing it up. Itlleads searches the state space
|searches the state space tree untilIt completely
optimal solution.
it has found a solution for theltree to get
problem. traverse the tree n
stateBranch-and-Bound
Traversal Backtracking traverses the
manner, DFS or BFS.
space tree by DFS(Depth Firstany
|Search) manner. involves a

Function Backtracking involves feasibility Branch-and-Bound


function. bounding function.
is used for solving
Problems Backtracking is used for solving| Branch-and-Bound
|Optimisation Problem.
|Decision Problem.
Branch-and-Bound as the optimum
Searching |In backtracking, the state space| In
may be present any where in
|tree is searched until the solution solution the tree need to
is obtained. the state space tree, so
|be searched completely.
Branch-and-Bound is less efficient.
Efficiency Backtracking is more efficient. solving Knapsack
Applications Useful in solving N-Queen Useful in
Salesman
Problem, Sum subset, Problem, Travelling
of
Hamilton cycle problem, graph Problem.
coloring problem
DAA-157
POPULAR PUBLICATIONS

Parameter Backtracking Branch and Bound


Solve Backtracking can solve almost Branch-
any problem. (chess, sudoku, any problem -and-Bound
|Used for
ete)
Typically backtracking is used to Branch and Cae s
Nodes
solve decision problems. |optimization
Nodes in stat space tree areNodes in
bound
problems.
Next move
explored in depth first tree. depth-first ortreebr may
Next move from current state can Next move is

Solution
|lead to bad choice. solution.
On successful search of solution| Entire always
state space tree
|in state space tree, search stops. to find optimal

10. a) Find the transitive closure of vertex Afrom the


soolution.
following graph:

b) Define the following terms:


(i) Directed Graph
(i) Undirected Graph
(ii) In-Degree and Out-Degree
(iv) Articulation Point
(v) Bridge
Chapter Name: GRAPH AND TREE TRAVERSAL ALGORITHMS
Answer:
a) Transitive closure of vertex A
A B C DEF G H

b) i) A directed graph, also called a digraph, is a graph in which the edges h


direction. This is usually indicated with an arrow on the edge; more formally, va
are vertices, an edge is an unordered pair (v,w}, while adirected edge, called an s
ordered pair (v, w) or (w,v).

DAA-158
ALCORITHHMS
DESIGN AND ANALYSS OF
are
undirected graph is graph, i.e., a set of objects
(called vertices or nodes) that
An
nccted together, where all the edges are bidirectional, An
undirected graph is
Onetimescalled.an undirected network. ofthe
vertex, the number of head ends adjacent to a vertex is calledtheindegree
) For a
and (called branching
the number of tail ends adjacent to a vertex is its outdegree
ertex
etorintrees).
vertex and
W)Avertex
is said to be an articulation point in a graph if removal of the increases
points
ssociated edges disconnectsthe graph. So, the removal of articulation sometimes
number of connected
the cutvertices.
components in a graph. Articulation points are
lled
disconnects the
Anedgein an undirected connected graph is a bridge if removing itbridgeis an edge
Paph. Foraa disconnected undirected graph,the definition is similar, a
removalthat increases the number of disconnected components.

11.a)
Differentiate between recursion and iteration. using Master's
b)Find thhe time complexity of the following recurrence relations
Theorem.

(0)

(i) T)=V2r +logn


ADefine little omega notation. Explain with an example.
Chapter Name: "INTRODUCTION"
Answer:
Differentiation between recursion and iteration:
Recursion Iteration
Property
Definition Function calls itself. A set of instructions repeatedly
executed.
Application For functions. For loops.
the termination condition for
Termination Through base case, where there When
will be no function call. |the iterator ceases to be satisfied.
complexity needs to
Usage Used when code size needs to beUsed when time
small, and time complexity is not be balanced against an expanded
an issue.
code size.
Smaller code size |Larger Code Size.
Code Size
Time Very high (generally exponential) |Relatively lower time complexity
Complexity time complexity. (generally polynomial-logarithmic).
Space |The space complexity is higher Space complexity is lower.
Complexity than iterations.
used.
Stack Here the stack is used to store local|Stack is not
variables when the function is
called.

DAA-159
POPULARPUBLICATIONS
Property Recursion
Speed Execution is slow since it has the Normally, it is
overhead of maintaining and as it doesn't utilizee t
Itefraastteiron
Memory
updating the stack. the sta
Kecursion uses more memory as Iteration uses less
compared tto recursion
|compared to iteration.
Overhead Possesses overhead of repeated|No overhead as

Infinite
function calls. calls in iteration.
If the recursive function does not| If the control
there ar
Repetition meet to a termination condition oriteration
the base case is not defined or is false or the statementCondtnei
never reached then it leads. to a reach the Control
terminationVarvabe
stack overflow error and there is a will cause
crash in infinite recursion. again and again.
infinite theooyC
chance that the an system may infinite loop, it uses

b)i) T(o)=2r|+T()=o(")
+log.n
For this recurrence relation we have a=(2),b =2 and f(n)= log, n. Thus
nn=() Since f(n)=o()=0 Vn) and thus the solutio
recurrence is T(n)=0(log, n).
c) Refer to Long Answer Type Question No. I.

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