DSA_LAB_Week_10
DSA_LAB_Week_10
Topic
Exploring Recursive Techniques in C++: A Practical and Analytical Approach.
Objective
1. Implement basic recursive functions in C++ to solve common computational problems
2. Understand the core principles and structure of recursive function calls, including base cases and recursive
steps.
3. Explore real-world programming scenarios where recursion provides elegant and efficient solutions.
4. Develop problem-solving skills through dry runs, trace tables, and complexity analysis of recursive
algorithms.
Outcomes
1. Demonstrate the ability to write and debug recursive functions in C++.
2. Identify base and recursive cases in a given problem and implement them effectively.
3. Analyze the time and space complexity of recursive solutions using Big-O notation.
4. Apply recursion to solve real-world problems and compare recursive solutions with iterative approaches.
Content
The following sections will be covered during this lab session:
1. Introduction to Recursion:
Begin with foundational recursion exercises such as calculating factorials, Fibonacci numbers,
and solving problems like sum of digits. These examples will help solidify the concept of base
and recursive cases.
2. Recursive Implementation of Linked List Operations:
Once the basics are clear, we will move toward applying recursion to linked lists:
• Singly Linked List: Implement core operations like insertion, traversal, and deletion
using recursive techniques.
• Doubly Linked List: Extend recursive concepts to handle forward and backward
navigation, including recursive insertion and deletion operations.
3. Time and Space Complexity Analysis:
Throughout the session, students will analyse the recursive implementations with respect to their
time and space complexity, comparing them with traditional iterative approaches.
Sample Output:
int arr[] = {12, 5, 18, 7, 3};
int size = 5;
Maximum element: 18
Requirements:
• Define a singly linked list node structure.
• Each operation must be implemented using recursion without any iterative loops.
• Handle edge cases like empty list, invalid positions, and value not found.
• Print the list after every insertion and deletion operation.
Constraints:
• You must implement the subset sum check recursively without loops.
• Use recursion to find and test the largest numbers as well.
• The array can contain positive integers only.
Sample Output:
Input: [2, 3, 5, 8, 13]
• Largest number is 13.
• Can 13 be formed by sum of any subset of [2, 3, 5, 8]?
• Yes, because 5 + 8 = 13.
• So, output: 13
Good Luck! Stay focused, think in steps, and enjoy the logic!