Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I need help with all of the following please help with answering each part my tutor hasn't been too helpful thank you 3.1 Learning Objective:
I need help with all of the following
please help with answering each part my tutor hasn't been too helpful thank you
3.1 Learning Objective: To write a recursive method. Instructions: See the instructions in $1.1 for what to submit for grading. This is not a complete program. N class H03_31 and save it in a file named H0331.java. When you are done, copy H03_31.java to your asu folder, i.e., to the same folder as the PDF. Problem: The sum of the first n positive integers, n 21, is: sum(n) = Ei and can easily be computed using a for loop: public int sumitoN(int n) { // You may assumen 21 int sum = 0; for (int i = 1; i pList. String pkey, int pBeginIdx, int pEndIdx) that searches last element. Beiden to i meended for and return the indexanlinlist - A A Jly Hello world" then the method shall return "dlrow olleH". Hint: The base case occurs when the length of s is either 0 or 1. When the length is 0, it means s is the empty string! "" and the reverse of the empty string is the empty string. When the length is 1, it means that you have a string such as "A" and the reverse of "A" is "A" (or in general, the reverse of a string of length s 1 is the string itself). Otherwise, retrieve the first character of s at index 0. call the character c (hint: read about the String.charAt method). Extract the substring t at indices 1..s.length() - 1 (read the Java API documentation for the String.sub- string() method). Then, call reverselt) which will return a string, let's call the string revT. Concatenate c onto the end of revT and then return the newly formed string. Testing: We will be testing your method using our driver routine. For testing on your end, write your own test driver in a class named H03_35_Test. Within H03_35_Test.run() you should call reverse() on many different strings, in- cluding the empty string, to verify your solution is correct. 4 Linear and Binary Search 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_41 and save it in a file named H03_11.java. When you are done. copy HO3_41.java to your asuriteid-h03 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 public int recLinear Search ArrayListStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started