Greedy?

What is the length of the longest path through the graph below? Calculate the length by adding the values of the nodes.

14 19 22 23 24 26

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.

4 solutions

Rohini Katla
Dec 14, 2017

4->7>2->10 is the longest path

4-7-3 is a longest path .,but how to answer 23?

Thomas Prabakar - 1 year, 5 months ago

I ran into the same issue; I believe this problem was made to make it clear that the greedy algorithm will not provide the best solution.

Pablo Cavallo - 1 year, 3 months ago
Jushtine Sanjuan
Mar 22, 2021

i answer and it was corrected, i start with the highest number which is 10 up, like a reverse in the first question. skl.

and im still confused haha!

Jushtine Sanjuan - 2 months, 3 weeks ago
Hp15T 2019
Jul 13, 2020

4->7->2->10

Karleigh Moore
May 4, 2016

The longest path comes from selecting the path: 4 to 7 to 2 to 10, which is 23 units long.

It should be made clear that we shouldn't try to calculate it with a greedy approach and get to 14

Deyan Dzhurov - 2 years, 8 months ago

how do you get this answer? Why you choose 10 instead of 1? Or why you choose 2 instead of 3?

Miraziz Khidoyatov - 2 years ago

Question states that you have to calculate the longest path, where the definition of "length" = "sum". That is why longest path means path with largest sum. Hope it clears your doubt.

Abhishek Kumar - 1 year, 9 months ago

Greedy Approach does not work for this, rather Recursive Approach is useful

Maheshwar Reddy - 1 year, 6 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...