(a) Design the recursive linear Search method that, when given a String [] S and a...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
(a) Design the recursive linear Search method that, when given a String [] S and a String to search for k, returns the index of k in S, and -1 if k is not in the array. Since this method is definitionally tail recursive, you should write a private helper method that actually performs the recursion. (b) Design the linear SearchLoop method that solves the problem using a loop. If you write tests for one of these methods, you should be able to propagate it to the other, so write plenty! For this problem you are not allowed to use an ArrayList or any helper methods, e.g., .contains, or methods from the Arrays class. You may (and should!) use a HashSet<Integer> to keep track of previously-seen peaks. (a) Joe the mountain climber has come across a large mountain range. He wants to climb only the tallest mountains in the range. Design the peakFinder method that returns an array H' of all the peaks in an int [] of mountain heights H. A peak p is defined as an element of h at index i such that p[i − 1] < p[i] and p[i] > p[i+1]. If i = 0 or i = |H|-1, Joe will not climb p[i]. Joe doesn't want to climb a mountain of the same height more than once, so you should not add any peaks that have already been added to H'. We present some test cases below. Hint: reuse the linear search algorithm from problem 1, except switch the String parameter for integers. peakFinder ({9, 13, 7, 2, 8}) -> {13} peakFinder ({8, 7, 8, 7, 8, 7, 8, 7}) -> {8} peakFinder({111, 27, 84, 31, 5, 9, 4, 3, 2, 1, 64}) -> {84, 9} peakFinder ({}) -> {} peakFinder({1}) -> {} peakFinder ({1, 2}) peakFinder({1, 2, 1}) peakFinder({1, 2, 3, 2, 1}) -> {} -> {2} -> {3} (a) A professor gives their students extra credit on an exam if they can guess the average within five percent of the actual average. Design the isGivenExtraCredit method that, when given an ArrayList<Double> D and a guess g, returns whether a student is given extra credit. (b) A village has members where each has a partner. These members are grouped in pairs inside an ArrayList<Integer> where each pair of indices represents a relationship of the village. I.e., A.get (21) and A.get (2i+1) are in a relationship. A couple is considered the wisest if they have the highest combined age. Write the wisest method that, when given an ArrayList<Integer> A, return a new ArrayList<Integer> containing the ages of the wisest pair. If there is a tie, return the pair that has the highest age overall. The order is not significant. We present a few test cases below. You can assume that there will always be an even number of village members. wisest ((31, 42, 43, 35, 21, 27, 24, 44} -> (43, 35) or {35, 43) wisest ({47, 51, 52, 48, 33, 67, 45, 35)-> (33, 67) or (67, 33} (c) Design the tokenize method that, when given a Strings and a char delimiter d, returns an ArrayList of tokens split at the delimiter. You must do this by hand; you cannot call any String methods (except .length and .charAt). (a) Design the recursive linear Search method that, when given a String [] S and a String to search for k, returns the index of k in S, and -1 if k is not in the array. Since this method is definitionally tail recursive, you should write a private helper method that actually performs the recursion. (b) Design the linear SearchLoop method that solves the problem using a loop. If you write tests for one of these methods, you should be able to propagate it to the other, so write plenty! For this problem you are not allowed to use an ArrayList or any helper methods, e.g., .contains, or methods from the Arrays class. You may (and should!) use a HashSet<Integer> to keep track of previously-seen peaks. (a) Joe the mountain climber has come across a large mountain range. He wants to climb only the tallest mountains in the range. Design the peakFinder method that returns an array H' of all the peaks in an int [] of mountain heights H. A peak p is defined as an element of h at index i such that p[i − 1] < p[i] and p[i] > p[i+1]. If i = 0 or i = |H|-1, Joe will not climb p[i]. Joe doesn't want to climb a mountain of the same height more than once, so you should not add any peaks that have already been added to H'. We present some test cases below. Hint: reuse the linear search algorithm from problem 1, except switch the String parameter for integers. peakFinder ({9, 13, 7, 2, 8}) -> {13} peakFinder ({8, 7, 8, 7, 8, 7, 8, 7}) -> {8} peakFinder({111, 27, 84, 31, 5, 9, 4, 3, 2, 1, 64}) -> {84, 9} peakFinder ({}) -> {} peakFinder({1}) -> {} peakFinder ({1, 2}) peakFinder({1, 2, 1}) peakFinder({1, 2, 3, 2, 1}) -> {} -> {2} -> {3} (a) A professor gives their students extra credit on an exam if they can guess the average within five percent of the actual average. Design the isGivenExtraCredit method that, when given an ArrayList<Double> D and a guess g, returns whether a student is given extra credit. (b) A village has members where each has a partner. These members are grouped in pairs inside an ArrayList<Integer> where each pair of indices represents a relationship of the village. I.e., A.get (21) and A.get (2i+1) are in a relationship. A couple is considered the wisest if they have the highest combined age. Write the wisest method that, when given an ArrayList<Integer> A, return a new ArrayList<Integer> containing the ages of the wisest pair. If there is a tie, return the pair that has the highest age overall. The order is not significant. We present a few test cases below. You can assume that there will always be an even number of village members. wisest ((31, 42, 43, 35, 21, 27, 24, 44} -> (43, 35) or {35, 43) wisest ({47, 51, 52, 48, 33, 67, 45, 35)-> (33, 67) or (67, 33} (c) Design the tokenize method that, when given a Strings and a char delimiter d, returns an ArrayList of tokens split at the delimiter. You must do this by hand; you cannot call any String methods (except .length and .charAt).
Expert Answer:
Answer rating: 100% (QA)
The image you have shared contains three separate programming problems each asking for a different algorithm to be designed or implemented I will addr... View the full answer
Related Book For
Algebra Graduate Texts In Mathematics 73
ISBN: 9780387905181
8th Edition
Authors: Thomas W. Hungerford
Posted Date:
Students also viewed these programming questions
-
Consider the differential equation y=22-y, with y(0)=-1. Given the step-size h = 0.1, solve it using the following methods, generating five steps for each: (2.1) The Taylor method. (2.2) The Euler...
-
Write a program to count the number of times the words in an input text file occur. The WordCount Structure Define a C++ struct called WordCount that contains the following data members: An array of...
-
Write a program to count the number of times the words in an input text file occur. The WordCount Structure Define a C++ struct called WordCount that contains the following data members: An array of...
-
Corporation Growth has $83,000 in taxable income, and Corporation Income has $8,300,000 in taxable income. (Refer to Table 2.3) What is the tax bill for each firm? Suppose both firms have identified...
-
The anchor ring is made of steel having specific weight st. Determine the surface area of the ring. The cross section is circular as shown. Given: st = 490 lb/ft3 a = 4 in b = 8 in
-
Business Finance is often associated with the maximisation of shareholder wealth and consideration of other stakeholder perspectives. Investors are constantly concerned about the future returns...
-
For each of the following sets of numbers, calculate a \(95 \%\) confidence interval for the mean \((\sigma\) known); before going through the steps in calculating the confidence interval, the sample...
-
Historically, technology firms have been the most aggressive users of stock-based compensation in the form of stock options granted to almost all employees of the firms. What is the rationale for...
-
ACME's COO is interested in measuring ACME's Inventory performance against the general performance of other firms in the industry. He has decided that Inventory Turns is the best measure of...
-
During December 2010, Amin Corp. manufactured products requiring 8,000 standard labor hours. The following variance and actual information is available: Labor rate variance ........ $4,500 U Labor...
-
Write a paper on " the Victimology"
-
Review a gamified system and look at the ways it provides scaffolding through feedback, modeling, collaboration and recursion.
-
Can you describe three early examples of systems that used games and play to accomplish specific goals?
-
What was Enrons first successful market?
-
Explain the benefits of the triangle of fraud action in comparison to the fraud triangle in courtroom testimonial situations.
-
Using Blooms revised taxonomy, evaluate the types of knowledge and learning occurring in a game or gamified system. What kind of knowledge is being gained; what kinds of skills? What domains...
-
Deontological theories define right action in terms of: Selectone: a. the virtuous agent. b. moral rules. c. Gods will. d. theirconsequences. Nonconsequentialist theories of morality are based on a...
-
Wholesalers Ltd. deals in the sale of foodstuffs to retailers. Owing to economic depression, the firm intends to relax its credit policy to boost productivity and sales. The firms current credit...
-
Proof that If u F is algebraic over K(X) for some X F then there exists a finite subset X' X such that u is algebraic over K(X').
-
If H is a maximal proper subgroup of a finite solvable group G, then [G: HJ is a prime power.
-
Determine the structure of the abelian group G defined by generators {a,b} and relations 2a + 4b = 0 and 3b = 0. Do the same for the group with generators {a,b,c,d} and relations 2a + 3b = 4a = 5c +...
-
Financial items for George Karatsis IT Services on 31 May 2024 are presented below in alphabetical order. Required (a) Prepare a statement of financial position similar to the one in figure 2.2. (b)...
-
During the year ended 30 June 2024, Skilled Services, a provider of temporary secretary personnel, had collected receipts from clients for a total value of \($250000.\) Wages of \($136000\) had been...
-
Rebecca Tallance operates a rent a dress business from her home. She keeps her accounting records for business activities completely separate from her records for personal activities. At 30 June...
Study smarter with the SolutionInn App