I need to prove a recursive algorithm. Normally this would be done using some integer value within the code as the base case for induction like when computing a factorial but with a graph traversal I have no idea where to begin. Here is my algorithm. Subscripts didn't convert.
Algorithm
Goal: Traverse a graph creating a depth-first spanning tree, and compute the Last descendent of each vertex that is the descendent vk that has the highest value of k
Input:
A connected graph G with vertices ordered v1, v2, v3 … vn
Output:
A spanning tree T where each vertex in T has had its Last vertex computed
Initialization Set each vertex to unvisited. Let ak denote a list of all vertices adjacent to vk. Let lk denote the Last descendent of vk. Let ck denote the list of all the children of vk in the spanning tree. Let dk denote the list of all vertices that are descendents of vk in the spanning tree including vk.
dfs(vk){
add vK to T
set v to visited
lk = vk
add vk to dk
foreach(vertex m in ak with lowest value of k){
add m to ck
add dfs(m) to dk
}
foreach(vertex vc in dk){
if( c > k){
lk = vc
}
}
if(k = 1)
return T
else
return dk
}
This is for a group project at school so I don't want the whole proof but a starting point and some direction would be greatly appreciated.