-2

enter image description here

What is the recurrence relation of the above algorithm? a step-by-step walkthrough would be appreciated.

panther1
  • 115
  • 9

1 Answers1

0

Your algorithm comprise for following steps :

  1. Initially it makes a linear search for the key, since it searches for all the elements it will add a complexity of -----> theta(n)
  2. If it finds the key, it returns
  3. Else, it recurses by passing it's child ------> T(child)

So, overall complexity : T(n) = T(n+1) + theta(n) ,

where T(n+1) will be the complexity for child node

Mayur Kulkarni
  • 1,306
  • 10
  • 28