Professional Documents
Culture Documents
Parul University Piet/Pit-It Department: Grade
Parul University Piet/Pit-It Department: Grade
Parul University Piet/Pit-It Department: Grade
PIET/PIT-IT DEPARTMENT
Grade:
PRATIK DHOLAKIYA ( 190303108012 )
Design and Analysis of Algorithms (203105301)
Assignment 1
2
PRATIK DHOLAKIYA ( 190303108012 )
Design and Analysis of Algorithms (203105301)
3
PRATIK DHOLAKIYA ( 190303108012 )
Design and Analysis of Algorithms (203105301)
2. T(n)=T(n-2)+logn………………if n>0
1………………………………………if n=0
4
PRATIK DHOLAKIYA ( 190303108012 )
Design and Analysis of Algorithms (203105301)
3. T(n)=2T(n/2)+n^2
5
PRATIK DHOLAKIYA ( 190303108012 )
Design and Analysis of Algorithms (203105301)
6
PRATIK DHOLAKIYA ( 190303108012 )
Design and Analysis of Algorithms (203105301)
2. T(n)=T(2n/3)+1
7
PRATIK DHOLAKIYA ( 190303108012 )
Design and Analysis of Algorithms (203105301)
3. T(n)=3T(n/4)+nlogn
8
PRATIK DHOLAKIYA ( 190303108012 )
Design and Analysis of Algorithms (203105301)
9
PRATIK DHOLAKIYA ( 190303108012 )
Design and Analysis of Algorithms (203105301)
5). Explain MST with suitable example (Prims and Kruskal algorithm).
10
PRATIK DHOLAKIYA ( 190303108012 )
Design and Analysis of Algorithms (203105301)
• Example
11
PRATIK DHOLAKIYA ( 190303108012 )
Design and Analysis of Algorithms (203105301)
The minimum spanning tree from a graph is found using the following
algorithms:
1. Prim's Algorithm
Prim's algorithm is a minimum spanning tree algorithm that takes a graph as
input and finds the subset of the edges of that graph which
• form a tree that includes every vertex
• has the minimum sum of weights among all the trees that can be formed from
the graph
• It falls under a class of algorithms called greedy algorithms that find the local
optimum in the hopes of finding a global optimum.
We start from one vertex and keep adding edges with the lowest weight until
we reach our goal.
ii. Find all the edges that connect the tree to new vertices, find the minimum and
add it to the tree
2. Kruskal's Algorithm
Kruskal's algorithm is a minimum spanning tree algorithm that takes a graph
as input and finds the subset of the edges of that graph which
• form a tree that includes every vertex
• has the minimum sum of weights among all the trees that can be formed from
the graph.
12
PRATIK DHOLAKIYA ( 190303108012 )
Design and Analysis of Algorithms (203105301)
• It falls under a class of algorithms called greedy algorithms that find the local
optimum in the hopes of finding a global optimum.
We start from the edges with the lowest weight and keep adding edges until
we reach our goal.
ii. Take the edge with the lowest weight and add it to the spanning tree. If adding
the edge created a cycle, then reject this edge.
13
PRATIK DHOLAKIYA ( 190303108012 )
Design and Analysis of Algorithms (203105301)
7). Apply the 0/1 Knapsack algorithm to the given data and find out
the best selected items to gain maximum Profit Value. N= 4 Items
(1,2,3,4) respective profit value v (10,40,30,50) and weight w is (5,
4,6,3). Consider Knapsack capacity W is 10.
14
PRATIK DHOLAKIYA ( 190303108012 )
Design and Analysis of Algorithms (203105301)
15
PRATIK DHOLAKIYA ( 190303108012 )
Design and Analysis of Algorithms (203105301)
16