Java recurrence relation with for loop -
public int algo(int n) { if (n == 1) { return 1; } algo(n/2); (int = 0; < 4; i++) { system.out.print(i); } return 0; }
i know recursive call mean t(n/2)
how loop affect recurrence relation?
edit: attempt.
i think loop run log n
times because run every time algo(int n)
run. , algo
run log n times because n keeps on being divided 2. also, loop runs 4 iterations. think add 4 log n
recurrence o(n) = t(n/2) + 4 log n.
since loop constant time , , not vary n . should not affect time complexity.
Comments
Post a Comment