So far, we have learned that we can perform repetitive tasks using loops. However, another way is by creating methods that call themselves. This programming technique is called recursion and, a method that calls itself within it's own body is called a recursive method. One use of recursion is to perform repetitive tasks instead of using loops, since some problems seem to be olved more naturally with recursion than with loops. To solve a problem using recursion, it is broken down into sub-problems. Each sub-problem is similar to the original problem, but smaller in size. You can apply the same approach to each ub-problem to solve it recursively. All recursive methods use conditional tests to either 1. stop or 2. continue the recursion. Each recursive method has the following characteristics: 1. end/terminating case: One or more end cases to stop the recursion. 2. recursive case: reduces the problem in to smaller sub-problems, until it reaches (becomes) the end case. nstructions : Complete the tasks listed below. See How To Approach This Lab and Instructions for Labs and Projects Several pieces of starter code have been provided within this lab (my-api) to help you practice recursion. You are expected to implement the bodies of the recursive methods listed below and include them in your lab report by providing a summary of their implementation. Where to find starter code in my-api package.class : modules.RecModule backage.class : testing.RecursionTest backage.class : sierpinski.fill.Viewer Task Lists 1. Complete the body for the recursive method fac(n) which computes n! (n factorial) for n >= 0. Note: n! = n(n - 1) (n - 2) (n - 2)... (2) (1), where n > 0 and zero factorial, O! = 1. 2. Complete the body for the recursive method sum(n) to compute the sum of the first n positive integers. 3. Complete the body for the recursive method pow(x,n) for computing æ", for a positive integer n, and real number x. 4. Complete the body for the recursive method isPalindrome(str) to determine if a string of text is a palindrome. This method accepts a String and returns true if the string reads the same forwards as backwards. The string is trivially true for empty or one(1) letter strings. Hint: You should make use of the subtring and charAt methods of the String.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%
Ex. 01 : Recursion
About
So far, we have learned that we can perform repetitive tasks using loops. However, another way is by creating methods that call themselves. This programming technique is called recursion
and, a method that calls itself within it's own body is called a recursive method. One use of recursion is to perform repetitive tasks instead of using loops, since some problems seem to be
solved more naturally with recursion than with loops.
To solve a problem using recursion, it is broken down into sub-problems. Each sub-problem is similar to the original problem, but smaller in size. You can apply the same approach to each
sub-problem to solve it recursively.
All recursive methods use conditional tests to either
1. stop or
2. continue the recursion.
Each recursive method has the following characteristics:
1. end/terminating case: One or more end cases to stop the recursion.
2. recursive case: reduces the problem in to smaller sub-problems, until it reaches (becomes) the end case.
Instructions : Complete the tasks listed below. See How To Approach This Lab and Instructions for Labs and Projects
Several pieces of starter code have been provided within this lab (my-api) to help you practice recursion. You are expected to implement the bodies of the recursive methods listed below
and include them in your lab report by providing a summary of their implementation.
Where to find starter code in my-api
package.class : modules.RecModule
package.class : testing.RecursionTest
package.class : sierpinski.fill.Viewer
Task Lists
1. Complete the body for the recursive method fac(n) which computes n! (n factorial) for n >= 0. Note: n! = n(n - 1) (n - 2) (n - 2)... (2) (1), where n > 0 and zero factorial, O! = 1.
2. Complete the body for the recursive method sum(n) to compute the sum of the first n positive integers.
3. Complete the body for the recursive method pow(x,n) for computing x", for a positive integer n, and real number x.
4. Complete the body for the recursive method isPalindrome(str) to determine if a string of text is a palindrome. This method accepts a String and returns true if the string reads the
same forwards as backwards. The string is trivially true for empty or one(1) letter strings. Hint: You should make use of the subtring and charAt methods of the String.
5. Run the Viewer of the Sierpinski Triangles and give a description of what you observed as it relates to recursion. Write a short summary (2-3 sentences is enough) of your observations.
Feel free to explain what the recursive solution is doing by checking out its ControlPanel.
Transcribed Image Text:Ex. 01 : Recursion About So far, we have learned that we can perform repetitive tasks using loops. However, another way is by creating methods that call themselves. This programming technique is called recursion and, a method that calls itself within it's own body is called a recursive method. One use of recursion is to perform repetitive tasks instead of using loops, since some problems seem to be solved more naturally with recursion than with loops. To solve a problem using recursion, it is broken down into sub-problems. Each sub-problem is similar to the original problem, but smaller in size. You can apply the same approach to each sub-problem to solve it recursively. All recursive methods use conditional tests to either 1. stop or 2. continue the recursion. Each recursive method has the following characteristics: 1. end/terminating case: One or more end cases to stop the recursion. 2. recursive case: reduces the problem in to smaller sub-problems, until it reaches (becomes) the end case. Instructions : Complete the tasks listed below. See How To Approach This Lab and Instructions for Labs and Projects Several pieces of starter code have been provided within this lab (my-api) to help you practice recursion. You are expected to implement the bodies of the recursive methods listed below and include them in your lab report by providing a summary of their implementation. Where to find starter code in my-api package.class : modules.RecModule package.class : testing.RecursionTest package.class : sierpinski.fill.Viewer Task Lists 1. Complete the body for the recursive method fac(n) which computes n! (n factorial) for n >= 0. Note: n! = n(n - 1) (n - 2) (n - 2)... (2) (1), where n > 0 and zero factorial, O! = 1. 2. Complete the body for the recursive method sum(n) to compute the sum of the first n positive integers. 3. Complete the body for the recursive method pow(x,n) for computing x", for a positive integer n, and real number x. 4. Complete the body for the recursive method isPalindrome(str) to determine if a string of text is a palindrome. This method accepts a String and returns true if the string reads the same forwards as backwards. The string is trivially true for empty or one(1) letter strings. Hint: You should make use of the subtring and charAt methods of the String. 5. Run the Viewer of the Sierpinski Triangles and give a description of what you observed as it relates to recursion. Write a short summary (2-3 sentences is enough) of your observations. Feel free to explain what the recursive solution is doing by checking out its ControlPanel.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Computational Systems
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education