Greedy Algorithms

Structure of a Greedy Algorithm:-

  1. Eager decision property: A worldwide (generally speaking) ideal arrangement can be reached by picking the ideal decision at each progression.
  2. Ideal foundation: An issue has an ideal base if an ideal answer for the whole issue contains the ideal answers for the sub-issues.

Restrictions of Greedy Algorithms:-


  1. Dijkstra’s Algorithm:-

Where you shouldn’t use Greedy approach?

Greedy vs Divide & Conquer vs Dynamic Programming

  1. Optimises by making the best choice at the moment
  2. Doesn’t generally track down the ideal arrangement, yet is quick
  3. Requires basically no memory
  1. Upgrades by separating a subproblem into less difficult adaptations of itself and utilizing multi-stringing and recursion to address
  2. Continuously tracks down the ideal arrangement, however is more slow than Greedy
  3. Requires some memory to recollect recursive calls
  1. Same as Divide and Conquer, yet advances by reserving the responses to each subproblem as not to rehash the computation twice.
  2. Continuously tracks down the ideal arrangement, however could be inconsequential on little datasets.
  3. Requires a ton of memory for remembrance/classification

Minimum Spanning Trees Using Prim’s Algorithm:-

  1. Make another tree with a solitary vertex (picked haphazardly)
  2. Of the multitude of edges not yet in the new tree, track down the base weighted edge and move it to the new tree.
  3. Rehash stage 2 until all vertices are in the tree

Is Greedy Optimal? Does Greedy Always Work?

  • Pick 3 divisions of coins. 1p, x, and under 2x yet more than x. We’ll pick 1, 15, 25.
  • Ask for change of 2 * second denomination (15)
[5, 0, 1]

Conclusion :-




Computer Science Student

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

“Gauge Theory” Science-Research, October 2021 — summary from Astrophysics Data System, DOE Pages…

Understanding centrality measures

University Math Lectures are Designed to Frustrate You

Math Anxiety Is Contagious

All You Need to Know About “Algorithms Complexity Analysis” and Big O

Mathematics’ Family Tree

Enemy AI: Player Detection in a 2D Game

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Shashwat Singh Raghav

Shashwat Singh Raghav

Computer Science Student

More from Medium

LeetCode 83- Remove Duplicates from Sorted List

Find the Town Judge 🚞

What is a Singly Linked List?

Time Complexity of Algorithms Explained with Examples