A shortest path algorithm with special input, solved with recursion
Overview
Given H amount of number h1,h2,...,hH and V amount of number v1,v2,...,vV
Horizontally H, Vertically V, H*V amount of vertex is arranged in a matrix.
These vertex make up a directional graph.
Let Vi,j be the vertex at ith row and jth column.
From every Vi,j, there are three directional edge going to Vi+1,j,Vi,j+1,Vi+1,j+1, assuming the vertex exists
Given H amount of number h1,h2,...,hH and V amount of number v1,v2,...,vV
,the cost of each of these edges is the absolute difference between hi and vj.
This algorithm finds the shortest path of the given graph
Input
H X
h1,h2,...,hH
v1,v2,...,vV
Output
three matrixes of H*V size.
The first matrix gives the cost of the edges going from the vertex.
The second matrix gives the total cost needed to go from 0,0 to that vertex.
The third matrix prints out the parent of the current vertex.