Recursion - Level 4

Dear Sciaku Learner you are not logged in or not enrolled in this course.

Please Click on login or enroll now button.

If you have any query feel free to chat us!

Happy Coding! Happy Learning!

Lecture 94:- Recursion - Level 4

At Level 4 of understanding recursion, let's explore even more advanced topics and complex problems involving recursion:

Advanced Divide and Conquer: The divide and conquer technique can be applied to more complex problems, such as finding the maximum subarray sum (Kadane's algorithm) or matrix multiplication (Strassen's algorithm).

Example - Maximum Subarray Sum using Divide and Conquer:

In this example, max_subarray_sum finds the maximum sum of a subarray using the divide and conquer technique.

Recursive Tree Traversals: Tree traversal algorithms (pre-order, in-order, post-order) can be implemented using recursion to visit nodes in a tree-based data structure.

Example - In-order Traversal:

In this example, in_order_traversal performs an in-order traversal of a binary tree.

Tail Call Optimization (TCO): Some programming languages and compilers optimize tail-recursive functions by reusing the current function's stack frame for the next recursive call, eliminating the need for additional stack space.

Mutually Recursive Functions with Tail Call Optimization: Tail call optimization can be applied to mutually recursive functions to optimize memory usage.

Recursive Sorting Algorithms: Recursive sorting algorithms like QuickSort and MergeSort use recursion to sort elements efficiently.

Expression Parsing and Evaluation: Recursive descent parsing is a top-down parsing technique used to parse expressions and evaluate them.

Recursion in Graph Algorithms: Graph algorithms like Depth-First Search (DFS) and Breadth-First Search (BFS) can be implemented using recursion.

Recursion at Level 4 delves into more advanced topics, such as advanced divide and conquer, recursive tree traversals, and recursion in graph algorithms. It also covers optimization techniques like tail call optimization and explores how recursion can be applied to more complex problems. Understanding these concepts and practicing their implementations will further enhance your problem-solving skills and algorithmic expertise.

pythonCopy code

class TreeNode:    def __init__(self, val=0, left=None, right=None):        self.val = val        self.left = left        self.right = right def in_order_traversal(root):    if root is None:        return    in_order_traversal(root.left)    print(root.val)    in_order_traversal(root.right)

pythonCopy code

def max_subarray_sum(arr, left, right):    if left == right:        return arr[left]    mid = (left + right) // 2    left_max = max_subarray_sum(arr, left, mid)    right_max = max_subarray_sum(arr, mid + 1, right)    cross_max = max_crossing_sum(arr, left, mid, right)    return max(left_max, right_max, cross_max) def max_crossing_sum(arr, left, mid, right):    left_sum = float('-inf')    sum = 0    for i in range(mid, left - 1, -1):        sum += arr[i]        left_sum = max(left_sum, sum)    right_sum = float('-inf')    sum = 0    for i in range(mid + 1, right + 1):        sum += arr[i]        right_sum = max(right_sum, sum)    return left_sum + right_sum

13. Recursion and Backtracking

Comments: 2

profile
@mk.info.work
17-Feb-2024, 10:20 PM

SCIAKU Team please upload 1st video of TREE please please please, please

profile
@na3744
23-Feb-2024, 02:52 AM

I bought this course, it worth it!

profile
@mk.info.work
15-Nov-2023, 10:25 PM

Hi i want to buy this course but you dont have master card payment method please let me know how i can buy it

profile
@sciaku1
11-Jan-2024, 03:23 PM

Dear mk.info.work, Now we have all types of payment options. If you need to purchase just checkout our official website

Frequently Asked Questions (FAQs)

How do I register on Sciaku.com?
How can I enroll in a course on Sciaku.com?
Are there free courses available on Sciaku.com?
How do I purchase a paid course on Sciaku.com?
What payment methods are accepted on Sciaku.com?
How will I access the course content after purchasing a course?
How long do I have access to a purchased course on Sciaku.com?
How do I contact the admin for assistance or support?
Can I get a refund for a course I've purchased?
How does the admin grant access to a course after payment?