Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Programming questions