Greedy algorithm

If there is a greedy algorithm that will traverse a graph, selecting the largest node value at each point until it reaches a leaf of the graph, what path will the greedy algorithm follow in the graph below?

4 to 5 to 8 4 to 7 to 3 4 to 5 to 4 to 9 4 to 7 to 2 to 10

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

19 solutions

Karleigh Moore
May 4, 2016

The algorithm will select the largest node at each step. 4 is at the root of the tree so that is included in our solution immediately. Next, we select between 5 and 7. 7 is the larget number so we add that to our path. Next, we select between 3 and 2. 3 is the larger number, so we put that in our solution path, and we have reached a graph leaf so the algorithm stops.

It doesnt work? I put 4-7-3 as my answer but it said i was incorrect.

ddd dwdwd - 2 years, 3 months ago

the algorithm of this question is too greedy to give us the real answer , it seems

Kegastam M - 2 years, 2 months ago

For sure lol

Flow Intern Mutong LI - 1 year, 10 months ago

it should be 4, 7, 3

Daniel Ngan - 1 year, 1 month ago
Paul Buchanan
Sep 20, 2020

4 is the root node of the tree. Next we select 7 which is the largest number compared to 5. Lastly we select 3 which is greater than 2.

Sam Lesser
May 15, 2021

Greedy Algos 🐽 , are short-sighted so: it takes the bigger option every time... 4-7-3

Yaman Wahsheh
Apr 20, 2021

It checks 5 or 7 -> goes to 7 -> then 3 or 2 -> Checks 3

Gaurav Tripathi
Apr 20, 2021

As we travel from top to bottom, the first node is having the maximum values as 4, At second node as 7 > 5, 7 gets selected. At 3rd node as 3>2 3 gest selected.

Huy Ngô
Oct 23, 2020

4->7->3. The largest node at 2nd level is 7. Next we need to decide between 2 and 3 and 3 is larger.

I understood very well.

The root is 4 and as greedy, it takes large one which is 7 and when it reach next, it takes 3 means 4-7-3

Benya Jamiu - 5 days, 11 hours ago
Julian Pro
Aug 30, 2020

greedy algorithm

Sip Test
Jan 28, 2020

because it greedy

Ankan Mitra
Nov 9, 2019

Well, first of all remember that a leaf node is that node which don't have any subnode Rest, the problem is too easy ......

Arunabh Saikia
Nov 4, 2019

Choose greatest number at each step !

Ahmad Sopian
Oct 18, 2019

In greedy algorithm case, value from path the bigges will way to get the good solution. And then, From 4, becouse 5 < 7, so greedy will choice 7. And next steps, 2 < 3, the choice is 3. And this is the end of path.

Shuvonil Ahmed
Aug 28, 2019

The greedy algorithm takes the largest value at each step of the tree.

Khánh Thiều
May 16, 2019

The greedy algorithm takes the biggest value at each step

Narongrit Neewong
May 15, 2019

easy to understand

Prasant Sahu
May 6, 2019

As per given tree : Root 4 traverse towards child 7 due to it is great then 5. Same thing it is continued for next level where 3 is greater then 2. Also, the leaf 3 have no any further nodes belonging to it.

by considering traversing of above tree it is 4 > 7 > 3

Prashant Mishra
Apr 28, 2019

4 -> 7 -> 3

Just select every maximu value in the adjacent node.

Gty Sdfgs
Apr 3, 2019

because im awesome

this is so sad

Prashant Mishra - 2 years, 1 month ago

selecting maximum value always

Sugnan M - 11 months, 2 weeks ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...