SlideShare a Scribd company logo
Recursion
Recursion
• Recursion is a programming technique in which a method can call
itself to fulfill its purpose
• A recursive definition is one which uses the word or concept being
defined in the definition itself
• In some situations, a recursive definition can be an appropriate way
to express a concept
• Before applying recursion to programming, it is best to practice
thinking recursively
Java Foundations, 4th Edition, Lewis/DePasquale/Chase 17 - 2
How Recursion works?
Infinite Recursion
• All recursive definitions must have a non-recursive part
• If they don't, there is no way to terminate the recursive path
• A definition without a non-recursive part causes infinite recursion
• This problem is similar to an infinite loop -- with the definition itself
causing the infinite “looping”
• The non-recursive part is called the base case
Java Foundations, 4th Edition, Lewis/DePasquale/Chase 17 - 4
Recursion in Math
• Mathematical formulas are often expressed recursively
• N!, for any positive integer N, is defined to be the product of all
integers between 1 and N inclusive
• This definition can be expressed recursively:
1! = 1
N! = N * (N-1)!
• A factorial is defined in terms of another factorial until the base case
of 1! is reached
Java Foundations, 4th Edition, Lewis/DePasquale/Chase 17 - 5
Recursive Programming
• A method in Java can invoke itself; if set up that way, it is called a
recursive method
• The code of a recursive method must handle both the base case and
the recursive case
• Each call sets up a new execution environment, with new parameters
and new local variables
• As always, when the method completes, control returns to the
method that invoked it (which may be another instance of itself)
Java Foundations, 4th Edition, Lewis/DePasquale/Chase 17 - 6
Recursive Programming
• Consider the problem of computing the sum of all the integers
between 1 and N, inclusive
• If N is 5, the sum is
1 + 2 + 3 + 4 + 5
• This problem can be expressed recursively as:
The sum of 1 to N is N plus the sum of 1 to N-1
Java Foundations, 4th Edition, Lewis/DePasquale/Chase 17 - 7
Recursive Programming
• The sum of the integers between 1 and N:
Java Foundations, 4th Edition, Lewis/DePasquale/Chase 17 - 8
Recursive Programming
• A recursive method that computes the sum of 1 to N:
public int sum(int num)
{
int result;
if (num == 1)
result = 1;
else
result = num + sum(num-1);
return result;
}
Java Foundations, 4th Edition, Lewis/DePasquale/Chase 17 - 9
Recursive Programming
• Tracing the recursive calls of the sum method
Java Foundations, 4th Edition, Lewis/DePasquale/Chase 17 - 10
Use recursion to add all of the numbers up to 10
public class Main {
public static void main(String[] args) {
int result = sum(10);
System.out.println(result);
}
public static int sum(int k) {
if (k > 0) {
return k + sum(k - 1);
} else {
return 0;
}
}
}
Recursion vs. Iteration
• Just because we can use recursion to solve a problem, doesn't mean
we should
• For instance, we usually would not use recursion to solve the sum of 1
to N
• The iterative version is easier to understand (in fact there is a formula
that computes it without a loop at all)
• You must be able to determine when recursion is the correct
technique to use
Java Foundations, 4th Edition, Lewis/DePasquale/Chase 17 - 13
Recursion vs. Iteration
• Every recursive solution has a corresponding iterative solution
• A recursive solution may simply be less efficient
• Furthermore, recursion has the overhead of multiple method
invocations
• However, for some problems recursive solutions are often more
simple and elegant to express
Java Foundations, 4th Edition, Lewis/DePasquale/Chase 17 - 14

More Related Content

Similar to Recursion.pptx

Recursion and looping
Recursion and loopingRecursion and looping
Recursion and looping
xcoolanurag
 
Recursion and Sorting Algorithms
Recursion and Sorting AlgorithmsRecursion and Sorting Algorithms
Recursion and Sorting Algorithms
Afaq Mansoor Khan
 
Ppt chapter12
Ppt chapter12Ppt chapter12
Ppt chapter12
Richard Styner
 
Lecture_7_StackAndRecursion (1).pptx
Lecture_7_StackAndRecursion (1).pptxLecture_7_StackAndRecursion (1).pptx
Lecture_7_StackAndRecursion (1).pptx
AbuHuraira729502
 
Recursion, debugging in c
Recursion, debugging in cRecursion, debugging in c
Recursion, debugging in c
Saule Anay
 
Types Of Recursion in C++, Data Stuctures by DHEERAJ KATARIA
Types Of Recursion in C++, Data Stuctures by DHEERAJ KATARIATypes Of Recursion in C++, Data Stuctures by DHEERAJ KATARIA
Types Of Recursion in C++, Data Stuctures by DHEERAJ KATARIA
Dheeraj Kataria
 
Java script – basic auroskills (2)
Java script – basic   auroskills (2)Java script – basic   auroskills (2)
Java script – basic auroskills (2)
BoneyGawande
 
ExpressionsInJavaScriptkkkkkkkkkkkkkkkkk
ExpressionsInJavaScriptkkkkkkkkkkkkkkkkkExpressionsInJavaScriptkkkkkkkkkkkkkkkkk
ExpressionsInJavaScriptkkkkkkkkkkkkkkkkk
kamalsmail1
 
Chapter 13
Chapter 13Chapter 13
Chapter 13
Terry Yoast
 
algorithm_6dynamic_programming.pdf
algorithm_6dynamic_programming.pdfalgorithm_6dynamic_programming.pdf
algorithm_6dynamic_programming.pdf
HsuChi Chen
 
PNP.pptx
PNP.pptxPNP.pptx
PNP.pptx
RishuRaj953240
 
PNP.pptx
PNP.pptxPNP.pptx
UNIT-V.ppt
UNIT-V.pptUNIT-V.ppt
UNIT-V.ppt
rajinooka
 
Python recursion
Python recursionPython recursion
Python recursion
ToniyaP1
 
Introduction to Recursion
Introduction to RecursionIntroduction to Recursion
Introduction to Recursion
Mansoor Bahramand
 
Python Programming unit5 (1).pdf
Python Programming unit5 (1).pdfPython Programming unit5 (1).pdf
Python Programming unit5 (1).pdf
jamvantsolanki
 
9781111530532 ppt ch13
9781111530532 ppt ch139781111530532 ppt ch13
9781111530532 ppt ch13
Terry Yoast
 
Introduction to Algorithms And DataStructure
Introduction to Algorithms And DataStructureIntroduction to Algorithms And DataStructure
Introduction to Algorithms And DataStructure
Prasanna996462
 
9. chapter 8 np hard and np complete problems
9. chapter 8   np hard and np complete problems9. chapter 8   np hard and np complete problems
9. chapter 8 np hard and np complete problems
Jyotsna Suryadevara
 
Pascal Programming Language
Pascal Programming LanguagePascal Programming Language
Pascal Programming Language
Reham AlBlehid
 

Similar to Recursion.pptx (20)

Recursion and looping
Recursion and loopingRecursion and looping
Recursion and looping
 
Recursion and Sorting Algorithms
Recursion and Sorting AlgorithmsRecursion and Sorting Algorithms
Recursion and Sorting Algorithms
 
Ppt chapter12
Ppt chapter12Ppt chapter12
Ppt chapter12
 
Lecture_7_StackAndRecursion (1).pptx
Lecture_7_StackAndRecursion (1).pptxLecture_7_StackAndRecursion (1).pptx
Lecture_7_StackAndRecursion (1).pptx
 
Recursion, debugging in c
Recursion, debugging in cRecursion, debugging in c
Recursion, debugging in c
 
Types Of Recursion in C++, Data Stuctures by DHEERAJ KATARIA
Types Of Recursion in C++, Data Stuctures by DHEERAJ KATARIATypes Of Recursion in C++, Data Stuctures by DHEERAJ KATARIA
Types Of Recursion in C++, Data Stuctures by DHEERAJ KATARIA
 
Java script – basic auroskills (2)
Java script – basic   auroskills (2)Java script – basic   auroskills (2)
Java script – basic auroskills (2)
 
ExpressionsInJavaScriptkkkkkkkkkkkkkkkkk
ExpressionsInJavaScriptkkkkkkkkkkkkkkkkkExpressionsInJavaScriptkkkkkkkkkkkkkkkkk
ExpressionsInJavaScriptkkkkkkkkkkkkkkkkk
 
Chapter 13
Chapter 13Chapter 13
Chapter 13
 
algorithm_6dynamic_programming.pdf
algorithm_6dynamic_programming.pdfalgorithm_6dynamic_programming.pdf
algorithm_6dynamic_programming.pdf
 
PNP.pptx
PNP.pptxPNP.pptx
PNP.pptx
 
PNP.pptx
PNP.pptxPNP.pptx
PNP.pptx
 
UNIT-V.ppt
UNIT-V.pptUNIT-V.ppt
UNIT-V.ppt
 
Python recursion
Python recursionPython recursion
Python recursion
 
Introduction to Recursion
Introduction to RecursionIntroduction to Recursion
Introduction to Recursion
 
Python Programming unit5 (1).pdf
Python Programming unit5 (1).pdfPython Programming unit5 (1).pdf
Python Programming unit5 (1).pdf
 
9781111530532 ppt ch13
9781111530532 ppt ch139781111530532 ppt ch13
9781111530532 ppt ch13
 
Introduction to Algorithms And DataStructure
Introduction to Algorithms And DataStructureIntroduction to Algorithms And DataStructure
Introduction to Algorithms And DataStructure
 
9. chapter 8 np hard and np complete problems
9. chapter 8   np hard and np complete problems9. chapter 8   np hard and np complete problems
9. chapter 8 np hard and np complete problems
 
Pascal Programming Language
Pascal Programming LanguagePascal Programming Language
Pascal Programming Language
 

More from VijalJain3

CN - Lecture 2.pptx
CN - Lecture 2.pptxCN - Lecture 2.pptx
CN - Lecture 2.pptx
VijalJain3
 
1. Introduction to Cyber Security.pptx
1. Introduction to Cyber Security.pptx1. Introduction to Cyber Security.pptx
1. Introduction to Cyber Security.pptx
VijalJain3
 
Random Class & File Handling.pptx
Random Class & File Handling.pptxRandom Class & File Handling.pptx
Random Class & File Handling.pptx
VijalJain3
 
RSA.pptx
RSA.pptxRSA.pptx
RSA.pptx
VijalJain3
 
Java-Intro.pptx
Java-Intro.pptxJava-Intro.pptx
Java-Intro.pptx
VijalJain3
 
AES.pptx
AES.pptxAES.pptx
AES.pptx
VijalJain3
 

More from VijalJain3 (6)

CN - Lecture 2.pptx
CN - Lecture 2.pptxCN - Lecture 2.pptx
CN - Lecture 2.pptx
 
1. Introduction to Cyber Security.pptx
1. Introduction to Cyber Security.pptx1. Introduction to Cyber Security.pptx
1. Introduction to Cyber Security.pptx
 
Random Class & File Handling.pptx
Random Class & File Handling.pptxRandom Class & File Handling.pptx
Random Class & File Handling.pptx
 
RSA.pptx
RSA.pptxRSA.pptx
RSA.pptx
 
Java-Intro.pptx
Java-Intro.pptxJava-Intro.pptx
Java-Intro.pptx
 
AES.pptx
AES.pptxAES.pptx
AES.pptx
 

Recently uploaded

Engine Lubrication performance System.pdf
Engine Lubrication performance System.pdfEngine Lubrication performance System.pdf
Engine Lubrication performance System.pdf
mamamaam477
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
bijceesjournal
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
KrishnaveniKrishnara1
 
Introduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptxIntroduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptx
MiscAnnoy1
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Christina Lin
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
Anant Corporation
 
Curve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods RegressionCurve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods Regression
Nada Hikmah
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
abbyasa1014
 
The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.
sachin chaurasia
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
MDSABBIROJJAMANPAYEL
 
Textile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdfTextile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdf
NazakatAliKhoso2
 
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENTNATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
Addu25809
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
171ticu
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
co23btech11018
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
Hitesh Mohapatra
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
Madan Karki
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
MIGUELANGEL966976
 
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
171ticu
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
SUTEJAS
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
IJECEIAES
 

Recently uploaded (20)

Engine Lubrication performance System.pdf
Engine Lubrication performance System.pdfEngine Lubrication performance System.pdf
Engine Lubrication performance System.pdf
 
Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...Comparative analysis between traditional aquaponics and reconstructed aquapon...
Comparative analysis between traditional aquaponics and reconstructed aquapon...
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
 
Introduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptxIntroduction to AI Safety (public presentation).pptx
Introduction to AI Safety (public presentation).pptx
 
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming PipelinesHarnessing WebAssembly for Real-time Stateless Streaming Pipelines
Harnessing WebAssembly for Real-time Stateless Streaming Pipelines
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
 
Curve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods RegressionCurve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods Regression
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
 
The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.The Python for beginners. This is an advance computer language.
The Python for beginners. This is an advance computer language.
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
 
Textile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdfTextile Chemical Processing and Dyeing.pdf
Textile Chemical Processing and Dyeing.pdf
 
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENTNATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
NATURAL DEEP EUTECTIC SOLVENTS AS ANTI-FREEZING AGENT
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
 
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
 
Understanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine LearningUnderstanding Inductive Bias in Machine Learning
Understanding Inductive Bias in Machine Learning
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
 

Recursion.pptx

  • 2. Recursion • Recursion is a programming technique in which a method can call itself to fulfill its purpose • A recursive definition is one which uses the word or concept being defined in the definition itself • In some situations, a recursive definition can be an appropriate way to express a concept • Before applying recursion to programming, it is best to practice thinking recursively Java Foundations, 4th Edition, Lewis/DePasquale/Chase 17 - 2
  • 4. Infinite Recursion • All recursive definitions must have a non-recursive part • If they don't, there is no way to terminate the recursive path • A definition without a non-recursive part causes infinite recursion • This problem is similar to an infinite loop -- with the definition itself causing the infinite “looping” • The non-recursive part is called the base case Java Foundations, 4th Edition, Lewis/DePasquale/Chase 17 - 4
  • 5. Recursion in Math • Mathematical formulas are often expressed recursively • N!, for any positive integer N, is defined to be the product of all integers between 1 and N inclusive • This definition can be expressed recursively: 1! = 1 N! = N * (N-1)! • A factorial is defined in terms of another factorial until the base case of 1! is reached Java Foundations, 4th Edition, Lewis/DePasquale/Chase 17 - 5
  • 6. Recursive Programming • A method in Java can invoke itself; if set up that way, it is called a recursive method • The code of a recursive method must handle both the base case and the recursive case • Each call sets up a new execution environment, with new parameters and new local variables • As always, when the method completes, control returns to the method that invoked it (which may be another instance of itself) Java Foundations, 4th Edition, Lewis/DePasquale/Chase 17 - 6
  • 7. Recursive Programming • Consider the problem of computing the sum of all the integers between 1 and N, inclusive • If N is 5, the sum is 1 + 2 + 3 + 4 + 5 • This problem can be expressed recursively as: The sum of 1 to N is N plus the sum of 1 to N-1 Java Foundations, 4th Edition, Lewis/DePasquale/Chase 17 - 7
  • 8. Recursive Programming • The sum of the integers between 1 and N: Java Foundations, 4th Edition, Lewis/DePasquale/Chase 17 - 8
  • 9. Recursive Programming • A recursive method that computes the sum of 1 to N: public int sum(int num) { int result; if (num == 1) result = 1; else result = num + sum(num-1); return result; } Java Foundations, 4th Edition, Lewis/DePasquale/Chase 17 - 9
  • 10. Recursive Programming • Tracing the recursive calls of the sum method Java Foundations, 4th Edition, Lewis/DePasquale/Chase 17 - 10
  • 11. Use recursion to add all of the numbers up to 10 public class Main { public static void main(String[] args) { int result = sum(10); System.out.println(result); } public static int sum(int k) { if (k > 0) { return k + sum(k - 1); } else { return 0; } } }
  • 12.
  • 13. Recursion vs. Iteration • Just because we can use recursion to solve a problem, doesn't mean we should • For instance, we usually would not use recursion to solve the sum of 1 to N • The iterative version is easier to understand (in fact there is a formula that computes it without a loop at all) • You must be able to determine when recursion is the correct technique to use Java Foundations, 4th Edition, Lewis/DePasquale/Chase 17 - 13
  • 14. Recursion vs. Iteration • Every recursive solution has a corresponding iterative solution • A recursive solution may simply be less efficient • Furthermore, recursion has the overhead of multiple method invocations • However, for some problems recursive solutions are often more simple and elegant to express Java Foundations, 4th Edition, Lewis/DePasquale/Chase 17 - 14