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

 .1 Learning Objective: To write a recursive method which searches a

.1 Learning Objective: To write a recursive method which searches a list for a key element. Instructions: See the instructions in S1.1 for what to submit for grading. This is not a complete program. Name your class H0841 and save it in a file named HO3_41.java. When you are done, copy HO3_41.java to your asuriteid-hos folder, i.e., to the same folder as the PDIF 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 (ArrayList pList, String pKey, int pBeginIdx, int pEndIdx) that searches pList elements pBeginldr up to and including pEndldr for pKey and returns the index of pKey in pList if found or-1 if not found. Hint: The base case is reached when pBeginldr is greater than pEndldz (what does this mean?). Otherwise, check to see if the element at pBeginldz is equal to pKey. If it is, then return pBeginldr. If it is not, then make a recursive method call which will search pList at elements pBeginidr+1 to pEndldr. Testing: We will be testing your method using our driver routine. For testing on your end, write your own driverrou tine in a class different than Hui_41. For testing, your method will be called in this manner to search the entire list: ArrayList list new ArrayList(); // ve wil1 populate list with several Strings int idx recLinearSearch(list, "the key", 0, list.sizeO -1; Note that if list is empty, the method should return -1 .1 Learning Objective: To write a recursive method which searches a list for a key element. Instructions: See the instructions in S1.1 for what to submit for grading. This is not a complete program. Name your class H0841 and save it in a file named HO3_41.java. When you are done, copy HO3_41.java to your asuriteid-hos folder, i.e., to the same folder as the PDIF 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 (ArrayList pList, String pKey, int pBeginIdx, int pEndIdx) that searches pList elements pBeginldr up to and including pEndldr for pKey and returns the index of pKey in pList if found or-1 if not found. Hint: The base case is reached when pBeginldr is greater than pEndldz (what does this mean?). Otherwise, check to see if the element at pBeginldz is equal to pKey. If it is, then return pBeginldr. If it is not, then make a recursive method call which will search pList at elements pBeginidr+1 to pEndldr. Testing: We will be testing your method using our driver routine. For testing on your end, write your own driverrou tine in a class different than Hui_41. For testing, your method will be called in this manner to search the entire list: ArrayList list new ArrayList(); // ve wil1 populate list with several Strings int idx recLinearSearch(list, "the key", 0, list.sizeO -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 Databases Questions!