Prove correctness of recursive algorithm
-
03-11-2019 - |
Question
I have this java function:
public int foo(ArrayList l, int n)
{
if(n <= 1)
return l.get(0);
if(l.get(0) < l.get(1))
l.remove(1);
else
l.remove(0);
foo(l, n-1);
}
So I figure to show that the algorithm is correct I would use an induction proof. However what I am not so sure about is how to go about doing the proof. Will I fist need to derive some sort of mathematical formula for this function and prove that?
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with cs.stackexchange