Greedy Algoritm Reflection

You might also like

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

The greedy algorithm design technique is a strategy for solving optimization

problems that involves building the solution incrementally by making locally optimal
choices at each step. It entails selecting the best option at each stage of the problem
without considering the long-term consequences of those choices. The greedy algorithm
is simple and efficient, making it a popular technique for a wide range of problems, from
task scheduling to finding the shortest path in a graph. However, because it only
considers the immediate consequences of each decision, it may not always produce the
best solution. As a result, it is critical to carefully evaluate the problem and determine
whether the greedy approach is appropriate.

Dijkstra's algorithm is a well-known algorithm for determining the shortest path in


a weighted graph. It operates by keeping a priority queue of vertices, with the shortest
known distance at the top. It expands its reach from a given source vertex, evaluating
neighboring vertices to update the distances. The algorithm selects the vertex with the
smallest known distance and adds it to the shortest path tree at each step. The
distances of its neighbors are then updated based on the weight of the connecting edge
and the distance to the newly added vertex. This process is repeated until all vertices
have been added to the shortest path tree or until the target vertex is reached. The
shortest path from the source to any other vertex in the graph is guaranteed by
Dijkstra's algorithm. However, non-negative edge weights are required, and it may be
inefficient on larger graphs.

You might also like