Summer 2023 Recursive Tracing & Programming

Summer 2023 Recursive Tracing & Programming
Slide Note
Embed
Share

Delve into Recursive Tracing, Recursion, and Recursive Programming in Summer 2023. Explore the concepts and practices through visualizations, agendas, and detailed lessons. Understand the power of recursion and its applications in problem-solving.

  • Summer 2023
  • Recursive
  • Programming
  • Tracing

Uploaded on Mar 01, 2025 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Recursive Tracing Hitesh Boinpally Summer 2023

  2. Agenda Recursion Intro Practice Visualizations Reminders Lesson 5 - Summer 2023 2

  3. Agenda Recursion Intro Practice Visualizations Reminders Lesson 5 - Summer 2023 3

  4. Road Map - Recursion Friday (Today) Introduce idea of recursion Goal: Understand idea of recursion and read recursive code Tuesday Practice reading recursive code Wednesday More complex recursive examples Goal: Identify recursive structure in problems and write recursive code Thursday Practice writing recursive code Lesson 5 - Summer 2023 4

  5. Road Map - Recursion Friday (Today) Introduce idea of recursion Goal: Understand idea of recursion and read recursive code Tuesday Practice reading recursive code Wednesday More complex recursive examples Goal: Identify recursive structure in problems and write recursive code Thursday Practice writing recursive code Lesson 5 - Summer 2023 5

  6. Recursion Intro Lesson 5 - Summer 2023 6

  7. Lesson 5 - Summer 2023 7

  8. Lesson 5 - Summer 2023 8

  9. Recursion Intro Recursion: Defining something in terms of itself Recursive Programming: Writing methods that call themselves to solve problems Helpful to solve specific problems Equally as powerful as iterative solutions Lesson 5 - Summer 2023 9

  10. Recursive Programming Two cases to always keep in mind: 1. Base Case: Stopping point, how to know we re done Easiest / smallest thing to calculate 2. Recursive Case: Do one step of the problem Pass on the work to the next method call Some problems may have multiple base / recursive cases! Lesson 5 - Summer 2023 10

  11. Agenda Recursion Intro Practice Visualizations Reminders Lesson 5 - Summer 2023 11

  12. slido.com code: #su_cse123 Recursive Tracing Practice public static int recursiveMystery(int n) { if (n == 0 || n == 1) { return 1; } else { return n * recursiveMystery(n - 1); } } Lesson 5 - Summer 2023 12

  13. slido.com code: #su_cse123 Recursive Tracing Practice public static int recursiveMystery(int n) { if (n == 0 || n == 1) { return 1; } else { return n * recursiveMystery(n - 1); } } Think of some example calls. What do they execute? recursiveMystery(0) recursiveMystery(2) recursiveMystery(4) Lesson 5 - Summer 2023 13

  14. slido.com code: #su_cse123 Recursive Tracing Practice public static int recursiveMystery(int n) { if (n == 0 || n == 1) { return 1; } else { return n * recursiveMystery(n - 1); } } recursiveMystery(4): Lesson 5 - Summer 2023 14

  15. Agenda Recursion Intro Practice Visualizations Reminders Lesson 5 - Summer 2023 15

  16. reverse Visualization public static void reverse(Scanner file) { if (file.hasNextLine()) { String text = file.nextLine(); reverse(file); System.out.println(text); } } file text Lesson 5 - Summer 2023 16

  17. Contents of file: 1. Suits 2. Barry 3. Modern Family 4. The Good Place reverse Visualization public static void reverse(Scanner file) { if (file.hasNextLine()) { String text = file.nextLine(); reverse(file); System.out.println(text); } } Reference to Scanner file text 1. Suits Lesson 5 - Summer 2023 17

  18. Contents of file: 1. Suits 2. Barry 3. Modern Family 4. The Good Place reverse Visualization public static void reverse(Scanner file) { if (file.hasNextLine()) { String text = file.nextLine(); reverse(file); System.out.println(text); } } Reference to Scanner file text 1. Suits Lesson 5 - Summer 2023 18

  19. Contents of file: 1. Suits 2. Barry 3. Modern Family 4. The Good Place reverse Visualization public static void reverse(Scanner file) { if (file.hasNextLine()) { String text = file.nextLine(); reverse(file); System.out.println(text); } } } } public static void reverse(Scanner file) { if (file.hasNextLine()) { String text = file.nextLine(); reverse(file); System.out.println(text); Reference to Scanner Reference to Scanner file file text text 1. Suits 2. Barry Lesson 5 - Summer 2023 19

  20. Contents of file: 1. Suits 2. Barry 3. Modern Family 4. The Good Place reverse Visualization public static void reverse(Scanner file) { if (file.hasNextLine()) { String text = file.nextLine(); reverse(file); System.out.println(text); } } } } public static void reverse(Scanner file) { if (file.hasNextLine()) { String text = file.nextLine(); reverse(file); System.out.println(text); Reference to Scanner Reference to Scanner file file text text 1. Suits 2. Barry Lesson 5 - Summer 2023 20

  21. Contents of file: 1. Suits 2. Barry 3. Modern Family 4. The Good Place reverse Visualization public static void reverse(Scanner file) { if (file.hasNextLine()) { String text = file.nextLine(); reverse(file); System.out.println(text); } } } } } } public static void reverse(Scanner file) { if (file.hasNextLine()) { String text = file.nextLine(); reverse(file); System.out.println(text); reverse(file); System.out.println(text); public static void reverse(Scanner file) { if (file.hasNextLine()) { String text = file.nextLine(); Reference to Scanner Reference to Scanner Reference to Scanner file file file text text 1. Suits 2. Barry 3. Modern Family text Lesson 5 - Summer 2023 21

  22. Contents of file: 1. Suits 2. Barry 3. Modern Family 4. The Good Place reverse Visualization public static void reverse(Scanner file) { if (file.hasNextLine()) { String text = file.nextLine(); reverse(file); System.out.println(text); } } } } } } } } public static void reverse(Scanner file) { if (file.hasNextLine()) { String text = file.nextLine(); reverse(file); System.out.println(text); reverse(file); System.out.println(text); reverse(file); System.out.println(text); public static void reverse(Scanner file) { if (file.hasNextLine()) { String text = file.nextLine(); if (file.hasNextLine()) { String text = file.nextLine(); public static void reverse(Scanner file) { Reference to Scanner Reference to Scanner Reference to Scanner Reference to Scanner file file file file text text 1. Suits 2. Barry 3. Modern Family 4. The Good Place text text Lesson 5 - Summer 2023 22

  23. Contents of file: 1. Suits 2. Barry 3. Modern Family 4. The Good Place reverse Visualization public static void reverse(Scanner file) { if (file.hasNextLine()) { String text = file.nextLine(); reverse(file); System.out.println(text); } } } } } } } } } } public static void reverse(Scanner file) { if (file.hasNextLine()) { String text = file.nextLine(); reverse(file); System.out.println(text); reverse(file); System.out.println(text); reverse(file); System.out.println(text); reverse(file); System.out.println(text); public static void reverse(Scanner file) { if (file.hasNextLine()) { String text = file.nextLine(); if (file.hasNextLine()) { String text = file.nextLine(); if (file.hasNextLine()) { String text = file.nextLine(); public static void reverse(Scanner file) { public static void reverse(Scanner file) { Reference to Scanner Reference to Scanner Reference to Scanner Reference to Scanner file Reference to Scanner file file file file text text 1. Suits 2. Barry 3. Modern Family 4. The Good Place text text text Lesson 5 - Summer 2023 23

  24. Contents of file: 1. Suits 2. Barry 3. Modern Family 4. The Good Place reverse Visualization public static void reverse(Scanner file) { if (file.hasNextLine()) { String text = file.nextLine(); reverse(file); System.out.println(text); } } } } } } } } public static void reverse(Scanner file) { if (file.hasNextLine()) { String text = file.nextLine(); reverse(file); System.out.println(text); reverse(file); System.out.println(text); reverse(file); System.out.println(text); public static void reverse(Scanner file) { if (file.hasNextLine()) { String text = file.nextLine(); if (file.hasNextLine()) { String text = file.nextLine(); public static void reverse(Scanner file) { Reference to Scanner Reference to Scanner Reference to Scanner Reference to Scanner file file Console output: 4. The Good Place file file text text 1. Suits 2. Barry 3. Modern Family 4. The Good Place text text Lesson 5 - Summer 2023 24

  25. Contents of file: 1. Suits 2. Barry 3. Modern Family 4. The Good Place reverse Visualization public static void reverse(Scanner file) { if (file.hasNextLine()) { String text = file.nextLine(); reverse(file); System.out.println(text); } } } } } } public static void reverse(Scanner file) { if (file.hasNextLine()) { String text = file.nextLine(); reverse(file); System.out.println(text); reverse(file); System.out.println(text); public static void reverse(Scanner file) { if (file.hasNextLine()) { String text = file.nextLine(); Reference to Scanner Reference to Scanner Reference to Scanner file file Console output: 4. The Good Place 3. Modern Family file text text 1. Suits 2. Barry 3. Modern Family text Lesson 5 - Summer 2023 25

  26. Contents of file: 1. Suits 2. Barry 3. Modern Family 4. The Good Place reverse Visualization public static void reverse(Scanner file) { if (file.hasNextLine()) { String text = file.nextLine(); reverse(file); System.out.println(text); } } } } public static void reverse(Scanner file) { if (file.hasNextLine()) { String text = file.nextLine(); reverse(file); System.out.println(text); Reference to Scanner Reference to Scanner file file Console output: 4. The Good Place 3. Modern Family 2. Barry text text 1. Suits 2. Barry Lesson 5 - Summer 2023 26

  27. Contents of file: 1. Suits 2. Barry 3. Modern Family 4. The Good Place reverse Visualization public static void reverse(Scanner file) { if (file.hasNextLine()) { String text = file.nextLine(); reverse(file); System.out.println(text); } } Reference to Scanner file Console output: 4. The Good Place 3. Modern Family 2. Barry 1. Suits text 1. Suits Lesson 5 - Summer 2023 27

  28. Agenda Recursion Intro Practice Visualizations Reminders Lesson 5 - Summer 2023 28

  29. Reminders Resub 0 Due tonight Updated to allow for C0 submissions 29

  30. Reminders Resub 0 Due tonight Updated to allow for C0 submissions Quiz 0 Monday (7/10) Logistic details to be posted today Topics: Linked Nodes, Linked Lists Take-home, open 8:30am 11:59pm Will get instant feedback Open collaboration (with a caveat), Open note Reach out ASAP with any extenuating circumstances 30

More Related Content