Ada MTE Presentation
Ada MTE Presentation
Submitted By:
Submitted to:
ANUJ (2K20/SE/21) ANUJ BORICHA (2K20/SE/22)
Ms. JYOTI BUDHWAR ANUPAMA(2K20/SE/23) ANURAAG KUMAR(2K20/SE/24)
Greedy Algorithm
➢ It is an algorithmic paradigm that builds up a solution piece by piece, always
choosing the next piece that offers the most obvious and immediate benefit.
➢ For example consider the Fractional Knapsack Problem. The local optimal
strategy is to choose the item that has maximum value vs weight ratio. This
strategy also leads to global optimal solution because we allowed to take
fractions of an item.
The algorithm never reverses the earlier decision even if the choice is wrong. It works in a top-down
approach.
This algorithm may not produce the best result for all the problems. It's
because it always goes for the local best choice to produce the global best
result.
However, we can determine if the algorithm can be used with any problem if
the problem has the following properties:
If an optimal solution to the problem can be found by choosing the best choice at
each step without reconsidering the previous steps once chosen, the problem can
be solved using a greedy approach. This property is called greedy choice property.
2. Optimal Substructure
If the optimal overall solution to the problem corresponds to the optimal solution to
its subproblems, then the problem can be solved using a greedy approach. This
property is called optimal substructure.
Advantages of Greedy Approach
● The algorithm is easier to describe.
● This algorithm can perform better than other algorithms (but, not in all cases).
For example, suppose we want to find the longest path in the graph below from root to leaf.
Let's use the greedy algorithm here.
1. Let's start with the root node 20. The weight of the right child is 3 and the weight of the left
child is 2.
2. Our problem is to find the largest path. And, the optimal solution at the moment is 3. So,
the greedy algorithm will choose 3.
However, it is not the optimal solution. There is another path that carries more weight (20 + 2
+ 10 = 32) as shown in the image below.
Spanning Tree
A connected subgraph ‘S’ of Graph G(V,E) is said to be a spanning tree of
graph G if and only if:
Connected subgraph S ( A
Graph G
spanning tree of graph G)
Some Possible spanning Tree from previous graph ‘G’
Properties of spanning tree
Following are a few properties of the spanning tree connected to graph G −
★ Removing one edge from the spanning tree will make the graph
disconnected, i.e. the spanning tree is minimally connected.
★ Adding one edge to the spanning tree will create a circuit or loop, i.e.
the spanning tree is maximally acyclic.
★ A spanning tree has n-1 edges, where 'n' is the number of nodes.
No. Of spanning Trees For complete graphs
The total number of spanning trees with n vertices that can be created
from a complete graph is equal to n^n-2.
The sum of the edges of the graph on right side is 16. Now,
some of the possible spanning trees created from the above
graph are -
So, the minimum spanning tree that is
selected from the above spanning
trees for the previously given weighted
graph is -
p3
Ste
p 4
Ste
Step 5
So, the graph produced in step 5 is the minimum spanning tree of the
previous show graph. The cost of the MST is -
Cost of MST = 4 + 2 + 1 + 3 = 10 units.