Topics: Recursion and Merge-sort Problem Description Please make sure to read the document fully before starting!...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Topics: Recursion and Merge-sort Problem Description Please make sure to read the document fully before starting! In this assignment, you will be tasked with writing methods that will solve some puzzles recursively. For some of them, you will need to use the merge method from Recursion Utils.java, which will be provided. NOTE: you can ignore any Checkstyle errors in Recursion Utils.java and Point.java since they are provided code files. Solution Description For this assignment, you will create the following class: Recursion.java Notes: 1. You will be able to use provided helper methods from Recursion Utils.java and Point.java. Review the Javadoc for those methods. 2. The methods in this assignment should be public and static, as they are procedures that do not use any instance data. 3. All methods in this assignment must use recursion or call recursive helper methods. a. INDICATE WHICH METHODS ARE RECURSIVE IN YOUR COMMENTS 4. Make sure to add all Javadoc comments to your methods Recursion.java This class will hold all the recursive methods you will be implementing. Methods: mergeSort ○ Takes in a String[] and returns a String[] containing the elements of the input sorted in ascending lexicographical order. O O O O ○ The input array will not be null or contain null entries. This algorithm must sort the input array using merge sort, as taught in lecture. When merging two arrays, you must use the merge method from Recursion Utils.java. Example 1: ◉ Input: ["Brian", "Alex", "David", "Charlie", "Aaron"] Output: ["Aaron", "Alex", "Brian", "Charlie", "David"] HINT: You may the copyOfRange method helpful in RecursionUtils.java mergeAll о Takes in a String[] [], where each index stores an ascending sorted array of Strings. O O O The input array will not be null or contain null entries. Returns a String[] containing all Strings from each index of the input in ascending lexicographical order. When merging two arrays, you must use the merge method from RecursionUtils.java. This method must be recursive or call recursive helper methods. ○ Example: Input: [["Alex", "Brian"], ["Aaron", "David"], ["Charlie"]] ■ Output: ["Aaron", "Alex", "Brian", "Charlie", "David"] count Duplicates Takes in a String[], which will be sorted in ascending lexicographical order. Returns an int, representing the number of duplicate elements in the input array. This method must be recursive, meaning that it will call itself at some point. ○ Example: Input: ["A", "A", "B", "C", "C", "C", "D"] ■ Output: 3 Reason: "A" is duplicated once, and "C" is duplicated twice. All other elements are unique. Thus, there are a total of three duplicates in the input. verify Palindrome о о Takes in a String. Returns a boolean, representing if the input string was a palindrome. If the input is an empty string, return true. o If the input is null, return false. A palindrome is a String that reads the same forwards and backwards Ex: The word "racecar" read backwards is still "racecar". Therefore, racecar is a palindrome. This method must be recursive, meaning it will call itself at some point This method should check if the String is palindrome regardless of casing (i.e. it should be case-insensitive). ○ Example: Input: Civic Output: true, "Civic" backwards is "civic" ○ Example: Input: "java" Output: false, "java" backwards is "avaj" • Example: Input: "tacocat" Output: true, "tacocat" backwards is "tacocat" numInteriorPoints o Takes in a Point[] and an int. 0 0 The first parameter (Point[]) represents the Cartesian coordinates for a set of points. Each index stores a Point, representing the coordinate pair of a point. The x field represents the x-coordinate. The y field represents the y-coordinate. The second parameter (int) represents the radius of a circle centered at the origin. Return an int representing the number of points that are strictly within the circle. HINT: Think about how you can use the Pythagorean Theorem in this situation This method must be recursive or use recursive helper methods. o Example: Input: [(1, 1) (0, 0) (3, 4) (5, 5)], 5 Output: 2, the first two points are within the circle of radius 5. The last two points have distance of 5 or more from the origin, and thus are not inside of the circle Allowed Imports To prevent trivialization of the assignment, you are not allowed to use any imports. Submission To submit, upload the files listed below to the corresponding assignment on Gradescope: Recursion.java Topics: Recursion and Merge-sort Problem Description Please make sure to read the document fully before starting! In this assignment, you will be tasked with writing methods that will solve some puzzles recursively. For some of them, you will need to use the merge method from Recursion Utils.java, which will be provided. NOTE: you can ignore any Checkstyle errors in Recursion Utils.java and Point.java since they are provided code files. Solution Description For this assignment, you will create the following class: Recursion.java Notes: 1. You will be able to use provided helper methods from Recursion Utils.java and Point.java. Review the Javadoc for those methods. 2. The methods in this assignment should be public and static, as they are procedures that do not use any instance data. 3. All methods in this assignment must use recursion or call recursive helper methods. a. INDICATE WHICH METHODS ARE RECURSIVE IN YOUR COMMENTS 4. Make sure to add all Javadoc comments to your methods Recursion.java This class will hold all the recursive methods you will be implementing. Methods: mergeSort ○ Takes in a String[] and returns a String[] containing the elements of the input sorted in ascending lexicographical order. O O O O ○ The input array will not be null or contain null entries. This algorithm must sort the input array using merge sort, as taught in lecture. When merging two arrays, you must use the merge method from Recursion Utils.java. Example 1: ◉ Input: ["Brian", "Alex", "David", "Charlie", "Aaron"] Output: ["Aaron", "Alex", "Brian", "Charlie", "David"] HINT: You may the copyOfRange method helpful in RecursionUtils.java mergeAll о Takes in a String[] [], where each index stores an ascending sorted array of Strings. Topics: Recursion and Merge-sort Problem Description Please make sure to read the document fully before starting! In this assignment, you will be tasked with writing methods that will solve some puzzles recursively. For some of them, you will need to use the merge method from Recursion Utils.java, which will be provided. NOTE: you can ignore any Checkstyle errors in Recursion Utils.java and Point.java since they are provided code files. Solution Description For this assignment, you will create the following class: Recursion.java Notes: 1. You will be able to use provided helper methods from Recursion Utils.java and Point.java. Review the Javadoc for those methods. 2. The methods in this assignment should be public and static, as they are procedures that do not use any instance data. 3. All methods in this assignment must use recursion or call recursive helper methods. a. INDICATE WHICH METHODS ARE RECURSIVE IN YOUR COMMENTS 4. Make sure to add all Javadoc comments to your methods Recursion.java This class will hold all the recursive methods you will be implementing. Methods: mergeSort ○ Takes in a String[] and returns a String[] containing the elements of the input sorted in ascending lexicographical order. O O O O ○ The input array will not be null or contain null entries. This algorithm must sort the input array using merge sort, as taught in lecture. When merging two arrays, you must use the merge method from Recursion Utils.java. Example 1: ◉ Input: ["Brian", "Alex", "David", "Charlie", "Aaron"] Output: ["Aaron", "Alex", "Brian", "Charlie", "David"] HINT: You may the copyOfRange method helpful in RecursionUtils.java mergeAll о Takes in a String[] [], where each index stores an ascending sorted array of Strings. O O O The input array will not be null or contain null entries. Returns a String[] containing all Strings from each index of the input in ascending lexicographical order. When merging two arrays, you must use the merge method from RecursionUtils.java. This method must be recursive or call recursive helper methods. ○ Example: Input: [["Alex", "Brian"], ["Aaron", "David"], ["Charlie"]] ■ Output: ["Aaron", "Alex", "Brian", "Charlie", "David"] count Duplicates Takes in a String[], which will be sorted in ascending lexicographical order. Returns an int, representing the number of duplicate elements in the input array. This method must be recursive, meaning that it will call itself at some point. ○ Example: Input: ["A", "A", "B", "C", "C", "C", "D"] ■ Output: 3 Reason: "A" is duplicated once, and "C" is duplicated twice. All other elements are unique. Thus, there are a total of three duplicates in the input. verify Palindrome о о Takes in a String. Returns a boolean, representing if the input string was a palindrome. If the input is an empty string, return true. o If the input is null, return false. A palindrome is a String that reads the same forwards and backwards Ex: The word "racecar" read backwards is still "racecar". Therefore, racecar is a palindrome. This method must be recursive, meaning it will call itself at some point This method should check if the String is palindrome regardless of casing (i.e. it should be case-insensitive). ○ Example: Input: Civic Output: true, "Civic" backwards is "civic" ○ Example: Input: "java" Output: false, "java" backwards is "avaj" • Example: Input: "tacocat" Output: true, "tacocat" backwards is "tacocat" numInteriorPoints o Takes in a Point[] and an int. 0 0 The first parameter (Point[]) represents the Cartesian coordinates for a set of points. Each index stores a Point, representing the coordinate pair of a point. The x field represents the x-coordinate. The y field represents the y-coordinate. The second parameter (int) represents the radius of a circle centered at the origin. Return an int representing the number of points that are strictly within the circle. HINT: Think about how you can use the Pythagorean Theorem in this situation O O O The input array will not be null or contain null entries. Returns a String[] containing all Strings from each index of the input in ascending lexicographical order. When merging two arrays, you must use the merge method from RecursionUtils.java. This method must be recursive or call recursive helper methods. ○ Example: Input: [["Alex", "Brian"], ["Aaron", "David"], ["Charlie"]] ■ Output: ["Aaron", "Alex", "Brian", "Charlie", "David"] count Duplicates Takes in a String[], which will be sorted in ascending lexicographical order. Returns an int, representing the number of duplicate elements in the input array. This method must be recursive, meaning that it will call itself at some point. ○ Example: Input: ["A", "A", "B", "C", "C", "C", "D"] ■ Output: 3 Reason: "A" is duplicated once, and "C" is duplicated twice. All other elements are unique. Thus, there are a total of three duplicates in the input. verify Palindrome о о Takes in a String. Returns a boolean, representing if the input string was a palindrome. If the input is an empty string, return true. o If the input is null, return false. A palindrome is a String that reads the same forwards and backwards Ex: The word "racecar" read backwards is still "racecar". Therefore, racecar is a palindrome. This method must be recursive, meaning it will call itself at some point This method should check if the String is palindrome regardless of casing (i.e. it should be case-insensitive). ○ Example: Input: Civic Output: true, "Civic" backwards is "civic" ○ Example: Input: "java" Output: false, "java" backwards is "avaj" • Example: Input: "tacocat" Output: true, "tacocat" backwards is "tacocat" numInteriorPoints o Takes in a Point[] and an int. 0 0 The first parameter (Point[]) represents the Cartesian coordinates for a set of points. Each index stores a Point, representing the coordinate pair of a point. The x field represents the x-coordinate. The y field represents the y-coordinate. The second parameter (int) represents the radius of a circle centered at the origin. Return an int representing the number of points that are strictly within the circle. HINT: Think about how you can use the Pythagorean Theorem in this situation This method must be recursive or use recursive helper methods. o Example: Input: [(1, 1) (0, 0) (3, 4) (5, 5)], 5 Output: 2, the first two points are within the circle of radius 5. The last two points have distance of 5 or more from the origin, and thus are not inside of the circle This method must be recursive or use recursive helper methods. o Example: Input: [(1, 1) (0, 0) (3, 4) (5, 5)], 5 Output: 2, the first two points are within the circle of radius 5. The last two points have distance of 5 or more from the origin, and thus are not inside of the circle Allowed Imports To prevent trivialization of the assignment, you are not allowed to use any imports. Allowed Imports To prevent trivialization of the assignment, you are not allowed to use any imports. Submission To submit, upload the files listed below to the corresponding assignment on Gradescope: Recursion.java Submission To submit, upload the files listed below to the corresponding assignment on Gradescope: Recursion.java
Expert Answer:
Answer rating: 100% (QA)
Based on the problem description provided heres the implementation of the Recursi... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Before you begin this assignment, be sure you have read the UMUC Family Clinic Case Study below and your Week 1 and Week2 syllabus readings, which discuss EHR functionality and Process...
-
Morse test is applicable only for SI engines: True/False andJustify
-
Nicholas Kerpatrick asks for your help concerning an NSF cheque. Explain to Nicholas (a) What an NSF cheque is, (b) How it is treated in a bank reconciliation, and (c) Whether it will require an...
-
(a) What volume in liters is a cube 20 cm on a side? (b) If the cube is filled with water, what is the mass of the water?
-
Build an experimental setup that lets you monitor messages on an embedded network.
-
An iron bar 2.00 cm x 3.00 cm x 10.0 cm at a temperature of 95C is dropped into a barrel of water at 25C. The barrel is large enough so that the water temperature rises negligibly as the bar cools....
-
Four Independent situations are described below. Each Involves future deductible amounts and/or future taxable amounts produced by temporary differences: Taxable income Future deductible amounts...
-
Provide briefly the reasons to choose the THREE listed firms below. Milux Corporation Berhad . Niche Capital Emas Holding Berhad. Panasonic Manufacturing Malaysia Berhad. Report the presentation and...
-
Ms. Disco visited a nightclub with her boyfriend. In the early hours of the morning, she needed a lift home because she and her boyfriend had a fight. A truck driver, Mr. Stalker, saw Ms. Disco...
-
What signs and symptoms of a mental health crisis is the person exhibiting? What would I initial response be to the person in the case study? What non-clinical intervention would I implement to help...
-
which tasks would most likely be completed by a group that has been formed for long-term assignments?
-
How to response this message;" I feel work disclosure level varies depending on the workplace culture and job requirements. I feel the line between personal and professional is between levels two and...
-
It is desired to produce an overhead product containing 80 mol% benzene from a feed mixture of 68 mol% benzene and rest toluene using ash distillation (i.e., distillation using a single stage/...
-
How, and to what extent, does the economy condition politics?
-
Which, if any, of the dichloroethene molecules drawn in Data Table II (3.) (4.) and (5.) are geometric isomers? A. B. C. D. cis-1,2-dichloroethene and trans-1,2-dichloroethene...
-
Explain the concept of partnering, including advantages and disadvantages.
-
Beths Bakery can comfortably produce 60 brownies in one day. If Beth takes some unusual measures, such as hiring her two aunts to help in the kitchen and work overtime, she can produce up to 100...
-
WAI uses two resources for each product that it builds: direct labor and machine time. From historical records,WAI calculates the following planning factors: Direct labor for standard corkscrew is...
-
A child on a sled slides down an icy slope, starting at a speed of \(2.5 \mathrm{~m} / \mathrm{s}\). The slope makes a \(15^{\circ}\) angle with the horizontal. After sliding \(10 \mathrm{~m}\) down...
-
A particle is accelerated such that its position as a function of time is given by \(\vec{x}=b t^{3} \hat{t}\), with \(b=1.0 \mathrm{~m} / \mathrm{s}^{3}\). What is the particle's acceleration as a...
-
You hold a puck at the top of an ice-covered ramp inclined at \(60^{\circ}\) with respect to the vertical. Your friend stands nearby on level ground and holds a ball at the same height \(h\) above...
Study smarter with the SolutionInn App