educative.io

The coding question and the graph ADT does not add up

After trying to solve a problem nearly for 1 hour getting error as vertex is not defined. Finally got that the ADT shows that the edges are list of numbers and not a list of Adjnode which is quite confusing. To any one trying to print edges just use the element directly instead of using element.vertex.


Course: https://www.educative.io/courses/algorithms-coding-interviews-python
Lesson: https://www.educative.io/courses/algorithms-coding-interviews-python/solution-find-all-connected-components-of-a-graph

Hello @Chandra_Kant_Sharma, We appreciate your effort and the time you’ve dedicated to solving this problem. The issue you encountered, where “vertex is not defined,” is related to a discrepancy between the provided code and how the graph was described in the lesson.

The code correctly represents edges as instances of AdjNode , and to print the edges, you should use temp.vertex , not just the element directly.

If you still think that the elements can be directly shown, please feel free to share your code.

Happy Learning