Skip to content

q04IsPathSumP

solutions.q04IsPathSumP

Question 4 [PY]

Given a weighted vertex graph \(G(V,E)\), a start node \(s\) and a target sum \(\sigma\).

Write an algorithm, or equivalently a python program (WAP) to inspect if there is a path from \(s\) such that adding up all the vertex weights along the path, equals the target sum.

Note: \(\forall v \in V\; \exists v.w\) that represents vertex weights.

Functions:

Name Description
q04IsPathSumP

Args:

q04IsPathSumP(G, s, targetSum)

Parameters:

Name Type Description Default
G Graph

Graph resolves into G.V and G.E.

required
s int

The start node.

required
targetSum int

The target sum.

required