CS Lab 6 Recursion I Solution

$30.00 $24.00

Goal In this lab you will design and implement recursive algorithms. The primary focus in this lab will be algorithms that make a single recursive call. Resources Chapter 7: Recursion Java Files RecursiveStringReplace.java TestReplace.java The goal is to complete a recursive method that will replace all occurrences of a given character with another character. Compile…

5/5 – (2 votes)

You’ll get a: zip file solution

 

Description

5/5 – (2 votes)

Goal

In this lab you will design and implement recursive algorithms. The primary focus in this lab will be algorithms that make a single recursive call.

Resources

  • Chapter 7: Recursion

Java Files

  • RecursiveStringReplace.java

  • TestReplace.java

The goal is to complete a recursive method that will replace all occurrences of a given character with another character.

Compile and run the main method in TestReplace.

Checkpoint: The program will run and get a null pointer exception.

Refer to the string replace recursive design from the pre-lab exercises and complete the method replace() in RecursiveStringReplace.java..

Final Checkpoint: Compile and run TestReplace. All tests should pass.

Post-Lab Follow-Ups

  1. Develop a recursive algorithm for computing the product of a sequence of odd values. (Eg. ProdOdd(11) = 1*3*5*7*9*11.) Use that method to develop a recursive algorithm for factorial that splits the problem into a product of even values and a product of odd values.

  1. Develop a recursive algorithm that given a and n, computes the sum

S = 1 + a + a2 + … + an

  1. Develop a recursive algorithm similar to string replace which works in place on an array of characters.

  1. Develop a recursive algorithm for computing the second most significant bit of a number n.

  1. Develop a recursive algorithm for computing the result of removing the second most significant bit from a number n.

Adapted from Dr. Hoot’s Lab Manual for Data Structures and Abstractions with Java

CS Lab 6 Recursion I Solution
$30.00 $24.00