Question: 4.1 Learning Objective: To write a recursive method which searches a list for a key element. Instructions: See the instructions in 1.1 for what to

 4.1 Learning Objective: To write a recursive method which searches a

4.1 Learning Objective: To write a recursive method which searches a list for a key element. Instructions: See the instructions in 1.1 for what to submit for grading. This is not a complete program. Name your class H03_.]{1 and save it in a le named H03_41.java \"When you are done; copy H03_41.java to your mmeidhg folder. i.e., to the same folder as the PDF. Problem: we discussed in the lectures how to write a linear search algorithm using a for loop which iterates over each element of a list. Linear search can also be implemented recursively. For this exercise. write a recursive method int recLinearSearch(ArrayListCZString} pLi st, String pKey, int pBeginIdX: int pEndIdx) that searches pLz'st elements pBeginIdI up to and including pEndIdr for pKey and returns the index of pKey in thst if found or 1 it not found. Hint: The base case is reached when pBeg'inIdr is greater than pEndde (what does this mean?) Otherwise. check to see if the element at pBeginIdI is equal to pKey. If it is. then return pBeginIdr. If it is not, then make a recursive method call which will search pList at elements pBeginIdr . l to pEmiIdr. Testing: \"He will be testing your method using our driver routine. For testing on your end. write your own driver rou tine in a class di'erent than H104_41. For testing. your method will be called in this manner to search the entire list: ArrayList list. = new ArrayListQO; // we will populate list with several Strings. . . int id}: = recLinearSearChClist, \"the key", 0, list.size() 1); Note that if list is empty, the method should return 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!