The following recursive function is initially invoked with an i value of 1. L is a list (array) of 10 integers. What does the function do? g(list L; positive integer i, integer x) if i>10 then return 0 else if L[i]=x then return 10 else return g(L,i+1,x) end if end if end function g
what class are you in?
its for CS discrete math, so it could be any i imagine
so if i is less than 10 and the array at index i does not equal x then recall the function with the index + 1
i believe its trying to find if the element x is in the array
or if x is in the current range of the array
agree?
yeah that makes sense, just seem to simple an answer in comparison to what this prof normally asks
what chapter is this in descrete?
i believe 4
our lecture doesnt really follow a book, we have 2 book references
It is a recursive function that has Base/terminating case: i>10, or L[i]=x Recursion goes from initially supplied value of i up to 10. If L contains x between L[i] and L[10], function return 10, otherwise function returns 0.
Join our real-time social learning platform and learn together with your friends!