function path = computePath(tree, parentIndices, currentIdx) % Backtrack from the goal index to the start index using the parent indices path = tree(:, currentIdx); while parentIndices(currentIdx) ~= 0 currentIdx = parentIndices(currentIdx); path = [tree(:, currentIdx), path]; end end