I am trying to learn about time complexity. I have done some research on the step method but am not sure how to call use it with a IF ELSE statement. The problem is below. I think the time complexity is O(n) but I am not sure.
The function is given is below with some of my //notes/ thoughts Any help in figuring this out would be greatly appreciated :)
FUNCTION fibonacci(number)
IF number < 1 THEN // constant operation, will only run once
ERROR
ELSE IF number = 1 or 2 THEN //constant operation, will only run once
RETURN 1
ELSE //these only run if the number isnt one or two so it could be N times- but not sure?
CALL fibonacci WITH number - 2 RETURNING twoBack
CALL fibonacci WITH number - 1 RETURNING oneBack
RETURN twoBack + oneBack
END IF
END FUNCTION
Aucun commentaire:
Enregistrer un commentaire