Uploaded by dosisoh633

IT 279 2023 08 22 Recursion

advertisement
For Thursday
š Watch Dynamic Classes video
š Prerequisite knowledge:
š C++ Pointers
š Dynamic Memory Management in C++
š Classes in C++
š Overloading Operators
š Submit Homework HW 1 on Recursion (Postponed to Wednesday)
Getting to Know You
š Introduce yourself on Teams in the appropriate channel by Wednesday. Include
why you chose computer science and something you like to do for fun.
š Be sure to check out the other introductions and even respond to them.
If you get stuck or confused
Come
Use
Come
Send
Do not struggle
Realize
Come for help early
Use Teams to reach out to me
Come to office hours
Send email
Not
Geeks4Geeks,
StackExchange,
GitHub, etc
Do not struggle alone
Realize that you can get help from your friends and me
Learning Together
š Help each other in class
š Help each other with concepts
š I have provided Teams for a reason
š Work together on your homework
š In groups of up to 4 people
š Complete your programs and exams by yourself except that you are
encouraged to reach out to me for help on the programs.
Using C++ on the Linux Machines
š Use the guide available on Canvas
š Recommended editor: Visual Studio Code
š Install the Live Share extension
š We are not using an IDE; we will compile from the command line
š Use g++ for compilation
NearPod Collaborate Board
Our Focus
Functionality
Correct
Algorithm/Data
Structure Use
Program and
Class Design
Code Clarity
Minor Focus on
Usability
Minor Focus on
Efficiency
Recursion
šWhat is it?
šHow does it work?
Weiss's 4 Rules of Recursion
Recursive Power Function
See Nearpod (use 6 for initial argument)
int func1(int num)
{
if(num < 5)
return 12;
else
return func1(num-1)+3;
}
Calculating Greatest Common Divisor
š Let's write the recursive int gcd(int num1, int num2) in C++
š What is the base case?
š When num1 and num2 are different, their GCD is the same as the GCD of the
smaller number and their difference
š Assume that num1 and num2 are positive integers
Recursive
Palindrome Checker
Download