From the wiki this is the algorithm and we know that final complexity is O(n) but how we reached to this , is my problem :
algorithm welzl is
input: Finite sets P and R of points in the plane |R| ≤ 3.
output: Minimal disk enclosing P with R on the boundary.
part 1: if P is empty or |R| = 3 then
return trivial(R)
part 2: choose p in P (randomly and uniformly)
part 3: D := welzl(P − {p}, R)
part 4: if p is in D then
return D
part 5: return welzl(P − {p}, R ∪ {p})
My try:
Easiest one, part 1 has O(1) time.
part 2 has O(1) time.
part 3 is something like T(n) = T(n-1).
part 4 is in O(1) time.
part 5 is something like T(n) = T(n-1) because we eliminate 1 point and increase R but we will work more with P so that would be the recursive equation.
If I writed correctly my analysis(and I'm sure it have incorrect parts) I don't know how to combine this 5 parts time complexity inorder to reach O(n).is the final equation like this?:$$T(n) = 2T(n-1)$$
but the final answer will be exponential .
If I made any mistake can someone help me please?