Ask your own question, for FREE!
Computer Science 20 Online
OpenStudy (anonymous):

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

OpenStudy (anonymous):

what class are you in?

OpenStudy (anonymous):

its for CS discrete math, so it could be any i imagine

OpenStudy (anonymous):

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

OpenStudy (anonymous):

i believe its trying to find if the element x is in the array

OpenStudy (anonymous):

or if x is in the current range of the array

OpenStudy (anonymous):

agree?

OpenStudy (anonymous):

yeah that makes sense, just seem to simple an answer in comparison to what this prof normally asks

OpenStudy (anonymous):

what chapter is this in descrete?

OpenStudy (anonymous):

i believe 4

OpenStudy (anonymous):

our lecture doesnt really follow a book, we have 2 book references

OpenStudy (mathmate):

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.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!