Skip to content

Latest commit

 

History

History
45 lines (29 loc) · 2.44 KB

Day 16 - Recursion Assignment.md

File metadata and controls

45 lines (29 loc) · 2.44 KB

Day 16: Recursion

Tasks/Activities:

Activity 1: Basic Recursion

  • Task 1: Write a recursive function to calculate the factorial of a number. Log the result for a few test cases.
  • Task 2: Write a recursive function to calculate the nth Fibonacci number. Log the result for a few test cases.

Activity 2: Recursion with Arrays

  • Task 3: Write a recursive function to find the sum of all elements in an array. Log the result for a few test cases.
  • Task 4: Write a recursive function to find the maximum element in an array. Log the result for a few test cases.

Activity 3: String Manipulation with Recursion

  • Task 5: Write a recursive function to reverse a string. Log the result for a few test cases.
  • Task 6: Write a recursive function to check if a string is a palindrome. Log the result for a few test cases.

Activity 4: Recursive Search

  • Task 7: Write a recursive function to perform a binary search on a sorted array. Log the index of the target element for a few test cases.
  • Task 8: Write a recursive function to count the occurrences of a target element in an array. Log the result for a few test cases.

Activity 5: Tree Traversal (Optional)

  • Task 9: Write a recursive function to perform an in-order traversal of a binary tree. Log the nodes as they are visited.
  • Task 10: Write a recursive function to calculate the depth of a binary tree. Log the result for a few test cases.

Feature Request:

  1. Factorial and Fibonacci Script: Write a script that includes recursive functions to calculate the factorial and Fibonacci numbers.
  2. Array Recursion Script: Create a script that includes recursive functions to find the sum and maximum element of an array.
  3. String Recursion Script: Write a script that includes recursive functions to reverse a string and check if a string is a palindrome.
  4. Recursive Search Script: Create a script that includes recursive functions for binary search and counting occurrences in an array.
  5. Tree Traversal Script: Write a script that includes recursive functions for in-order traversal and depth calculation of a binary tree (optional).

Achievement:

By the end of these activities, students will:

  • Understand and implement basic recursion.
  • Apply recursion to solve problems with arrays and strings.
  • Use recursion for searching and counting elements in arrays.
  • Perform traversal and calculate tree depth using recursion (optional).